...

View Full Version : recognizing a url in php form



juniorx
05-11-2004, 04:12 PM
Basically i need advice on how to recognize a url. Say a user fills in info for a news page and half way through the news info he types http://www.cnn.com (into a textbox) Basically i want to know how the server will post this as a link rather then as a long string of text that other users can't click

Edit: Notice in my post it automatically creates the link to cnn website without me having to type some code.

cpradio
05-11-2004, 04:38 PM
Do a search on php.net for preg_replace or ereg_replace, you will find the code that does this in the comments of other users.

sidney
05-11-2004, 04:39 PM
do somthing like below


$txt = "how to recognize a url. Say a user fills in info for a news page and half HTTPS://www.cnn.com way through the news info he types http://www.cnn.com";
$txt=preg_replace("//(https?:\/\/[^ ]*)/si"," <a href=\"$1\">$1</a> ",$txt);
echo $txt;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum