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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.