Jump to content

changing preg_replace


darkfreaks

Recommended Posts

can anyone tell me how to modify the following statement so its an ereg_replace and not preg for some reason it will not work in my function if it is not ereg_replace ???

 

<?php
$text = preg_replace("/[^a-z]+[^:\/\/](www\.".
"[^\.]+[\w][\.|\/][a-zA-Z0-9\/\*\-\?\&\%\=\,\.]+)/",
" <a href=http://\\3>\\3</a>", $text);?>

Link to comment
https://forums.phpfreaks.com/topic/91828-changing-preg_replace/
Share on other sites

OK, I fooled around with it and got it working:

 

<?php
$str = "Please go visit http://www.mysite.com/index.php?action=whatever";
$str .= " Please go visit http://www.mysite.com";
$str .= " Please go visit www.mysite.com";





function transformUrl($str){
    $str=utf8_decode(urldecode($str));
    $str=eregi_replace("(^| |>)(www([.]?[a-zA-Z0-9_/-?])[^< ]*)", "\\1<a href=\"http://\\2\">\\2</a>", $str);
    $str=eregi_replace("(^| |>)(http://www([.]?[a-zA-Z0-9_/-?])[^< ]*)", "\\1<a href=\"\\2\">\\2</a>", $str);
    $str=eregi_replace("(^| |>)(http://([.]?[a-zA-Z0-9_/-?])[^< ]*)", "\\1<a href=\"\\2\">\\2</a>", $str);
    return utf8_encode($str);
}

echo transformUrl($str);

?>

Link to comment
https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470313
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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