damonlee Posted December 29, 2006 Share Posted December 29, 2006 Hello,I have a script that reads from a text file, the text file contains http://www.someurl.com. which the end user will edit at their discrection.I need the echo command to find the url and format it as a link. I know I must be missing something simple, like calling the find_url function within the loop...Here is my code:<?phpfunction find_url($string){//"www." $pattern_preg1 = '#(^|\s)(www|WWW)\.([^\s<>\.]+)\.([^\s\n<>]+)#sm'; $replace_preg1 = '\\1<a href="http://\\2.\\3.\\4" target="_blank" class="link">\\2.\\3.\\4</a>';//"http://" $pattern_preg2 = '#(^|[^\"=\]]{1})(http|HTTP|ftp)(s|S)?://([^\s<>\.]+)\.([^\s<>]+)#sm'; $replace_preg2 = '\\1<a href="\\2\\3://\\4.\\5" target="_blank" class="link">\\2\\3://\\4.\\5</a>'; $string = preg_replace($pattern_preg1, $replace_preg1, $string); $string = preg_replace($pattern_preg2, $replace_preg2, $string); return $string;}?><? $filename = "uploadScript/files/recentEventsTXT.txt"; //here's the filename$id = fopen($filename, "r"); //open the filewhile ($data = fgetcsv($id, filesize($filename), "|")) //start a loop "|" sets pipe as delimiter$table[] = $data; //put each line into its own entry in the $table arrayfclose($id); //close fileecho "<table cellspacing='2'>\n";foreach($table as $row){echo "<tr>"; foreach($row as $data) echo "<td width='400' height='18'>$data</td>";echo "</tr>\n";}echo "</table>\n";?>I didn't write this code myself, they were examples found elsewhere, I'm trying to make them work together. Thank you Link to comment https://forums.phpfreaks.com/topic/32143-solved-format-url-from-a-text/ Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 Try...[code=php:0]echo "<td width='400' height='18'>".find_url($data)."</td>";[/code] Link to comment https://forums.phpfreaks.com/topic/32143-solved-format-url-from-a-text/#findComment-149172 Share on other sites More sharing options...
damonlee Posted December 29, 2006 Author Share Posted December 29, 2006 Thank you! What a fast reply. Much grato 8) Link to comment https://forums.phpfreaks.com/topic/32143-solved-format-url-from-a-text/#findComment-149176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.