Devenvj Posted March 15, 2014 Share Posted March 15, 2014 Hello Guys, Need a small help, as this is complex for me. With PHP 5.4, our server throws "Deprecated: Function eregi_replace() is deprecated" for a file and need you experts help to convert below 3 lines and replace it with preg_replace function. Can any one help with new lines of below code : $body_html = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1">\\1</a>', $body_html); $body_html = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2">\\2</a>', $body_html); $body_html = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $body_html); Thank you & Appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/ Share on other sites More sharing options...
Ch0cu3r Posted March 15, 2014 Share Posted March 15, 2014 (edited) You need to change eregi_replale to preg_replace, then apply delimiters to the start and end of your regex pattern and lastly use the case insenstive ( letter i ) pattern modifier Example for the first one // escape pattern delimiter + + case insensitve pattern modifier // | | $body_html = preg_replace('~(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.\~#?&//=]+)~i', '<a href="\\1">\\1</a>', $body_html); // ^ ^ // | | // +-------------- pattern delimiters ------------+ Edited March 15, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/#findComment-1472688 Share on other sites More sharing options...
Devenvj Posted March 15, 2014 Author Share Posted March 15, 2014 Wow, thanks .. You explanation style is great. Ill check the same and update tomor as the script allowed to runs once a day.. Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/#findComment-1472694 Share on other sites More sharing options...
Devenvj Posted March 16, 2014 Author Share Posted March 16, 2014 Hey Ch0cu3r I did the above changes in all 3 lines, Although the Deprecated error is gone, a new warning pops up, below : Line 1 : $body_html = preg_replace('~(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)~i', '<a href="\\1">\\1</a>', $body_html); Line 2 : $body_html = preg_replace('~([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)~i', '\\1<a href="http://\\2">\\2</a>' $body_html); Line 3 : $body_html = preg_replace('~([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})~i', '<a href="mailto:\\1">\\1</a>', $body_html); New warning : "Warning: preg_replace(): Unknown modifier '#'" (For line 1 & 2) Kindly help further... Thx Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/#findComment-1472762 Share on other sites More sharing options...
Ch0cu3r Posted March 16, 2014 Share Posted March 16, 2014 (edited) You are using a ~ as the pattern delimiter, therefore when using a ~ within your regex pattern you need to escape it, like how I showed in my escape pattern delimiter comment from my first post (a \ before the ~). Edited March 16, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/#findComment-1472766 Share on other sites More sharing options...
Devenvj Posted March 16, 2014 Author Share Posted March 16, 2014 Oops how can i miss that ...You showed me that .. Thanks bro and cross fingers for tomor. I will finally update you and close this... Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/#findComment-1472768 Share on other sites More sharing options...
Solution Devenvj Posted March 17, 2014 Author Solution Share Posted March 17, 2014 Finally done, Thanks to Ch0cu3r and this forum.. Quote Link to comment https://forums.phpfreaks.com/topic/286988-eregi_replace-to-preg_replace-code-help/#findComment-1472860 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.