-1

how to convert below ereg statements to preg_replace

 $message = ereg_replace("http://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $message);
 $message = ereg_replace("(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $message);
hakre
  • 193,403
  • 52
  • 435
  • 836

1 Answers1

0
$message = preg_replace('~http://([.]?[a-zA-Z0-9_/-])*~', '<a href="$0" target="_blank">$0</a>', $message);
$message = preg_replace('~(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)~', '$1<a href="http://$2" target="_blank">$2</a>', $message);
xdazz
  • 158,678
  • 38
  • 247
  • 274