Jump to content

how to detect the insertion of link in a textarea forum ???


mina

Recommended Posts

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

 

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;
?>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.