We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
preg_replace urls; preg_replace urls help
Topic Started: Jun 20 2005, 09:06 AM (392 Views)
Cool Dude 2k
<?php echo "Linux"; ?>
[ *  * ]
Code:
 
<?php
$Test = "http://Test.com/Test/Test/ CD2k";
$Test = preg_replace("/(http:\/\/|ftp:\/\/|https:\/\/)(.*?)$/isxS", "<a href=\"$1$2\">$1$2</a>", $Test);
echo $Test;
?>

I want it to stop at the space and not replace urls in html tags like the image tag and anchor tag.
Heres a Test of it. http://cd2k.madpage.com/Test/preg.php
Offline Profile Quote Post Goto Top
 
Dead Midgets
Member
[ *  * ]
I think this code is what you want.

Code:
 
<?php
$Test = "http://Test.com/Test/Test/ CD2k";
$Test = preg_replace('{(http://.+?)(\s|$)}', '<a href="\1">\1</a>\2', $Test);
echo $Test;
?>


sorry not sure how to add https: and ftp: in there.
Offline Profile Quote Post Goto Top
 
Cool Dude 2k
<?php echo "Linux"; ?>
[ *  * ]
Dead Midgets
July 14, 2005 03:42 PM
I think this code is what you want.

Code:
 
<?php
$Test = "http://Test.com/Test/Test/ CD2k";
$Test = preg_replace('{(http://.+?)(\s|$)}', '<a href="\1">\1</a>\2', $Test);
echo $Test;
?>


sorry not sure how to add https: and ftp: in there.

Yep Thanks very much. ^_^
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply