Jump to content

preg_replace urls with html <a> tags


ajmsake

Recommended Posts

I found this on the net...

<?php$text = "this is a paragraph of text with an url embeded.  [url="http://www.google.com/"]http://www.google.com/[/url] is a search engine.  I'd like to replace the url with the html <a> tag";$text .= " but the below is not working.  Another search engine is [url="http://www.yahoo.com/foo/search.html?nothing=nope"]http://www.yahoo.com/foo/search.html?nothing=nope[/url] I keep getting 'Delimiter must"; $text .= " not be alphanumeric or backslash'";preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '<a href="\0">\0</a>', $text);?>

Any ideas? :) I'm trying to replace all urls be it starting with http:// with <a href="url">url</a>

Link to comment
Share on other sites

I found this on the net...
<?php$text = "this is a paragraph of text with an url embeded.  [url="http://www.google.com/"]http://www.google.com/[/url] is a search engine.  I'd like to replace the url with the html <a> tag";$text .= " but the below is not working.  Another search engine is [url="http://www.yahoo.com/foo/search.html?nothing=nope"]http://www.yahoo.com/foo/search.html?nothing=nope[/url] I keep getting 'Delimiter must"; $text .= " not be alphanumeric or backslash'";preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '<a href="\0">\0</a>', $text);?>

Any ideas? :) I'm trying to replace all urls be it starting with http:// with <a href="url">url</a>

See....! just like it did above in the posting... ugh...
Link to comment
Share on other sites

You match the email address (search Google) and then replace it with <a href="mailto:$0">$0</a>.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...