Jump to content

ereg_replace to preg_replace


scepanmali

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/
Share on other sites

I know that I need to put delimiters, but it is to complicated for me :(

 

If you know where to put them, please help out.

Did you read the link?

it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.

yes I did, but not sure if I need to do this just for first parameter.

I did this and please tell me if it's ok now:

 

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

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

Ok, I don't know why are you like that.

 

You could just say: you need to put it here and here

and one line explanation and this will be over in one post

If I knew all of this, I wouldn't post here.

 

Sorry if I am stupid for you guys.

And you could have just read the documentation.  It's there for many reasons, one of them being to prevent posts like this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.