I want to convert every pattern >>’number’ (eg: >>4) on users’ threads automatically to
<a href="#4">>>4</a>
So I made this function but it’s not working.
Could you tell me what is wrong with the function?
function autolink($content) {
$pattern = "/>>[0-9]/i" ;
$replacement = "<a href=\"#\\0\">>>\\0</a>";
return preg_replace($pattern, $replacement, $content, -1);
This function works well. This function automatically converts the urls into clickable hyperlink. I don’t know why the first function isn’t working.
function autolink2($contents) {
$pattern = "/(http|https|ftp|mms):\/\/[0-9a-z-]+(\.[_0-9a-z-]+)+(:[0-9]{2,4})?\/?"; // domain+port
$pattern .= "([\.~_0-9a-z-]+\/?)*"; // sub roots
$pattern .= "(\S+\.[_0-9a-z]+)?" ; // file & extension string
$pattern .= "(\?[_0-9a-z#%&=\-\+]+)*/i"; // parameters
$replacement = "<a href=\"\\0\">\\0</a>";
return preg_replace($pattern, $replacement, $contents, -1);}
Try this
Tested and works.