1

I am working for a non-profit and i'm not an expert in PHP.

I need to replace the following code:

$status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $status);

When I attempt to modify it to preg_replace, I get an error every different way I try to exit the code.

CodeZombie
  • 5,367
  • 3
  • 30
  • 37

1 Answers1

0

This will do the job:

$statut = preg_replace('~[a-z]+://[^<>\s]+[\w/]~i', '<a href="$0">$0</a>', $statut);

But if the goal of this replacement is to keep all urls and transform them into links, you must change the pattern a little. And, why not, test them with filter_validate_url

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125