mina Posted February 16, 2011 Share Posted February 16, 2011 i am facing a problem regarding the insertion of of link in a text area is not detected but the output is a normal text "unlike facebook comments" is there any php functions ??? thanks in advance Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted February 17, 2011 Share Posted February 17, 2011 Have you tried a regular expression (like preg_*) on your text data? Quote Link to comment Share on other sites More sharing options...
mina Posted February 17, 2011 Author Share Posted February 17, 2011 this is the code i am using nl2br(_post['comment']; so the forum can recognize the line only but not the links thanks in advance Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted February 17, 2011 Share Posted February 17, 2011 What format of links are we talking about: a. the a-tag link like <a href=xxxx>yyyyy</a> b. the url type such as http://www.mysite.com c. within bb-code such as [link=xxxxx]yyy[/link] Quote Link to comment Share on other sites More sharing options...
mina Posted February 19, 2011 Author Share Posted February 19, 2011 hello programmers , i think u don't get my question so here is some explanation i used a textarea to take comments from users and save it to mysql database and output it to the website so what i wanted to do if a user sends a link as a comment at the output time it appears as a a hyperl ink like facebook comments thanks in advance Quote Link to comment Share on other sites More sharing options...
sdowney1 Posted February 19, 2011 Share Posted February 19, 2011 I did this when echoing a result into a div the a href creates a link to mysearch3.php the $row[1] is what the user sees If ($on =="off"){echo '<a href=mysearch3.php?page='.$page_num.'&id='.$row[0].'>'.$row[1].'</a>';} Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 19, 2011 Share Posted February 19, 2011 You'll have to use a regular expression. Quote Link to comment Share on other sites More sharing options...
sdowney1 Posted February 19, 2011 Share Posted February 19, 2011 so it seems you need to search the string to see if it could be a link. If it looks like a link, then add on the a href stuff to make it work as a link Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted February 23, 2011 Share Posted February 23, 2011 It is still not quite clear to me, but let's be practical: When you are looking form www.xxx.yy text that has to be converted into links, have a try at the following regular expression: <?php $pattern_url = '~(?>[a-z+]{2,}://|www\.)(?:[a-z0-9]+(?:\.[a-z0-9]+)?@)?(??:[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])(?:\.[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])+|(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:/[^\\/:?*"<>|\n]*[a-z0-9])*/?(?:\?[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?(?:&[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?)*)?(?:#[a-z0-9_%.]+)?~i'; $text = 'This is www.mysystem.com where the text can be found. Also at www.yourcom.nl you find some comments'; /** ----------------------------------------- Prefix www.xxxxx.yy string with http:// ----------------------------------------- */ preg_match_all($pattern_url, $text, $matches); for ($i=0; $i < count($matches[0]); $i++) { if (substr($matches[0][$i],0,4) == 'www.' ) $text = str_replace($matches[0][$i], 'http://'.$matches[0][$i], $text); } /** ---------------------------------------------------- Replace free-format URLs with <a href...> elements ---------------------------------------------------- */ $text = preg_replace($pattern_url,"<a href=\"\\0\">\\0</a>", $text); echo $text; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.