Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2016
    Posts
    17
    Thanks
    17
    Thanked 4 Times in 4 Posts

    Convert url in a string to hyperlinks

    If you are working with forums, blogs or even a normal form submission, many times you end us asking user for a website. Using the function, the URL string would automatically convert to a hyperlink.

    PHP Code:
    function makeClickableLinks($text
    {  
     
    $text eregi_replace('(((f|ht){1}tp://)[[email protected]:%_+.~#?&//=]+)',  
     
    '<a href="\1">\1</a>'$text);  
     
    $text eregi_replace('([[:space:]()[{}])(www.[[email protected]:%_+.~#?&//=]+)',  
     
    '\1<a href="http://\2">\2</a>'$text);  
     
    $text eregi_replace('([_.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',  
     
    '<a href="mailto:\1">\1</a>'$text);  
      
    return 
    $text;  
    }
    $text "This is my first post on http://blog.koonk.com";
    $text makeClickableLinks($text);
    echo 
    $text
    Online PHP Debugger
    (built-in Vim mode)
    http://phpio.net

  2. #2
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,589
    Thanks
    10
    Thanked 161 Times in 156 Posts
    Don't post obsolete code. It is completely useless. eregi_replace has been completely removed from Php and was deprecated hundreds of Php versions ago way back in Php 5.3

    PHP: eregi_replace - Manual
    Last edited by benanamen; Dec 10th, 2016 at 06:19 PM.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  3. Users who have thanked benanamen for this post:

    phpio.net (Dec 11th, 2016)


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •