0

How would I make these two previous ereg_replace expressions work with preg_match?

http://([.]?[a-zA-Z0-9_/-])*|  

and

(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)

adding code from comment

preg_replace("http://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\" target=\"_blank\">\\0</a>"
DevZer0
  • 13,433
  • 7
  • 27
  • 51

1 Answers1

0

Just add delimiter arround the regex:

http://([.]?[a-zA-Z0-9_/-])*

becomes

/http:\/\/([.]?[a-zA-Z0-9_\/-])*/

or, better

~http://([.]?[a-zA-Z0-9_/-])*~

Same for the second one:

(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)

becomes:

~(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)~
Toto
  • 89,455
  • 62
  • 89
  • 125