简体   繁体   中英

PHP: warning preg_replace

I have been having a really hard time debugging this error since the past 2 days...googled for every possible solution bu failed...would be really helpful if anyone could help me out with it:

Warning: preg_replace() [function.preg-replace]: Unknown modifier '$' in C:\xampp\htdocs\wi_class_files\autoMakeLinks.php on line 7

The code is:

class autoActiveLink {

    function makeActiveLink($originalString){

        $newString = preg_replace("[[:alpha:]]+://[^[:space:]]+[[:alnum:]/]i/","\\0", $originalString);
        return $newString;
    }

}

You forgot your delimiters (at the beginning AND at the end of your mask)

class autoActiveLink {  
    function makeActiveLink($originalString) {  
        $newString = preg_replace("#[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]#i","<a href=\"\\0\" target=\"_blank\">\\0</a>", $originalString);
        return $newString;
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM