I had this code but now I need to change it to newer preg_replace function
Can someone help me to do it please?

Here is the code:

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

Thanks in advance.

Can you please add a before and after example to this. preg needs a start and end character around the regex, but I'm not sure if that is enough. You can try this:

$newString = preg_replace("%[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]%","<a href=\"\\0\" target=\"_blank\">\\0</a>", $originalString);

If this doesn't work, please post the requested samples.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.