scepanmali Posted April 26, 2012 Share Posted April 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/ Share on other sites More sharing options...
xyph Posted April 26, 2012 Share Posted April 26, 2012 Just add delimiters. http://www.php.net/manual/en/regexp.reference.delimiters.php More reading http://php.net/manual/en/reference.pcre.pattern.posix.php Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340817 Share on other sites More sharing options...
scepanmali Posted April 26, 2012 Author Share Posted April 26, 2012 Thanks for the quick reply. 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. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340821 Share on other sites More sharing options...
Maq Posted April 26, 2012 Share Posted April 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340822 Share on other sites More sharing options...
scepanmali Posted April 26, 2012 Author Share Posted April 26, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340825 Share on other sites More sharing options...
Jessica Posted April 26, 2012 Share Posted April 26, 2012 Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340827 Share on other sites More sharing options...
Maq Posted April 26, 2012 Share Posted April 26, 2012 yes I did, but not sure if I need to do this just for first parameter. it is required that the pattern is enclosed by delimiters. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340828 Share on other sites More sharing options...
scepanmali Posted April 26, 2012 Author Share Posted April 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340849 Share on other sites More sharing options...
xyph Posted April 26, 2012 Share Posted April 26, 2012 We aren't here to fix your code, we're here to help you learn. The links I provided explained everything. If you want to be spoon-fed, expect to pay. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1340856 Share on other sites More sharing options...
Maq Posted April 27, 2012 Share Posted April 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261660-ereg_replace-to-preg_replace/#findComment-1341128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.