1

Possible Duplicate:
Regex URL Match

im trying to create functions that will give my chat clickable links.... here are the functions i've created

<?php
//makes links starting with http clickable
    function makehttpclickable($text){
        return preg_replace('!(((f|ht)tp://)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $text);
}
//makes links starting www. http clickable

function clickywww($www){
    return preg_replace('!((www)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $www);
}
/function that gives me an error!
function clickydotcom($noob){
    return preg_replace('!([-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)(\.com)!i'.'!([-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)(\.com)!f', '<a href="$1.com$f">$1.com</a>', $noob);
}

I've been getting an unkown modifier error. Warning: preg_replace() [function.preg-replace]: Unknown modifier '!' So Anyways any help would be nice on how i can make all types of links clickable

Community
  • 1
  • 1
ramr
  • 1,019
  • 1
  • 10
  • 17

1 Answers1

0

This code will do it

 <?php
 $input= "website is http://www.xyz.com";
 $clickable = preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%]+*', '<a href="$0">$0</a>', $input);
 echo $clickable;
 ?> 

I have made some modification according to above solution in your function. This code will make ftp, http, etc links clickable

 <?php
 function makehttpclickable($input){
 return preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%]+*', '<a href="$0">$0</a>', $input);
 }
 ?> 

Hope this helps

Naeem Ul Wahhab
  • 2,465
  • 4
  • 32
  • 59