[:space:]" /> [:space:]" /> [:space:]"/>

Need to replace deprecated ereg_replace

56 views Asked by At

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.

1

There are 1 answers

0
Casimir et Hippolyte On

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