http://www.webmasterworld.com Welcome to WebmasterWorld Guest from 38.103.63.17
register, login, search, glossary, subscribe, help, library, PubCon, announcements , recent posts, unanswered posts
Accredited PayPal World Seller
Home / Forums Index / The Webmaster World / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & dreamcatcher & eelixduppy & jatar k

PHP Server Side Scripting

  
Recognizing URLs in Text, and Parsing them into Hyperlinked HTML urls
kazisdaman3


#:3268857
 10:59 am on Mar. 2, 2007 (utc 0)

Hi everyone, couldn't find the answer from searching.

PHP & MySQL:

How can I recognize a url, and turn it into a HTML hyperlinked url.

without, having like [url]http://www.example.com

I got the above to work, but can I get it to recongize without the [url]and have it convert the url to a hyperlinked url?

Thanks for the help, I appreciate you guys help all the time, thank you!

Warmly,
Wesley

eelixduppy


#:3268890
 12:00 pm on Mar. 2, 2007 (utc 0)

Try something like this.

$pattern = "/http:\/\/(www\.)?([^.]+\.[^.\s]+\.?[^.\s]*)/i";
$replace = "<a href='http://\\1\\2'>http://\\1\\2</a>";
$string = preg_replace($pattern,$replace,$string);
echo $string;

Where $string is the text. Just a couple notes about this pattern:
1) The URI MUST have "http://" before it
2) It works for URIs formatted in the following ways
>>>http://www.example.foo
>>>http://www.example.foo.foo #having two
>>>http://example.foo
>>>http://example.foo.foo #having two
>>>http://foo.exmaple.foo #pretty much the same as above

I know this is missing a possibility but I figured I'd get you on the right track ;)

Good luck!

kazisdaman3


#:3268906
 12:19 pm on Mar. 2, 2007 (utc 0)

Wow,

! Thanks a ton again eelixduppy!

I owe you a christmas gift now!x3

Thank you so much!

-WES

 

Home / Forums Index / The Webmaster World / PHP Server Side Scripting
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of WebmasterWorld Inc.
© WebmasterWorld Inc. / SearchEngineWorld 1996-2008 all rights reserved