ztealmax Posted December 13, 2006 Share Posted December 13, 2006 Hi is there anyway for a script to read a text file and if it finds some kind of url for example www.phpfreaks.comit automaticly makes a clickable link of it?my read text script:[code]<?PHP require_once("theme.php");?><?php// set file to read$file = $_GET['text'];// open file $fh = fopen($file, 'r') /*or die('Could not open file!')*/;// read file contents$data = fread($fh, filesize($file)) /*or die('Could not read file!')*/;// close file fclose($fh); // print file contents ?><DIV class="smallblacktext"><pre><? echo $data;?></DIV></pre>[/code]Too many questions today? ;) hehe sorry about that, im full of question ;D Link to comment https://forums.phpfreaks.com/topic/30483-check-content-of-text-file-and-if-it-finds-www-it-makes-a-link/ Share on other sites More sharing options...
mainewoods Posted December 13, 2006 Share Posted December 13, 2006 Try preg_replace_callback()http://www.php.net/manual/en/function.preg-replace-callback.php[code]<?phpfunction create_link($matches) { //do some work here so a complete url is produced //with $matches, etc. 'http://...' $link = '<a href="' . $matches . '">' . $matches . '</a>'; return $link;}echo preg_replace_callback( "**regular expression here**", "create_link", //function name! $data); //your variable?> [/code] if someone could help you with the actual regular expression to use there, that code should be good to go Link to comment https://forums.phpfreaks.com/topic/30483-check-content-of-text-file-and-if-it-finds-www-it-makes-a-link/#findComment-140461 Share on other sites More sharing options...
ztealmax Posted December 14, 2006 Author Share Posted December 14, 2006 Thank you verry much :)ill try it Link to comment https://forums.phpfreaks.com/topic/30483-check-content-of-text-file-and-if-it-finds-www-it-makes-a-link/#findComment-140914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.