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. 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 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 ------------+ 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.. 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 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 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 ~). 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... 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...
Devenvj Posted March 17, 2014 Author Share Posted March 17, 2014 Finally done, Thanks to Ch0cu3r and this forum.. 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
Archived
This topic is now archived and is closed to further replies.