{"id":663,"date":"2013-05-18T19:34:01","date_gmt":"2013-05-18T17:34:01","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=663"},"modified":"2013-05-19T12:58:19","modified_gmt":"2013-05-19T10:58:19","slug":"663","status":"publish","type":"post","link":"http:\/\/www.extradrm.com\/?p=663","title":{"rendered":"How to Fix `ereg is deprecated` errors in PHP 5.3"},"content":{"rendered":"<p>If you upgraded to PHP 5.3 like the famous oscommerce 2.2, chances are high you\u2019re going to run into a few warnings or <strong>deprecated function messages.<\/strong><\/p>\n<p>An example is the <strong>ereg family <\/strong>of functions, which are gone for good, as they were slower and felt less familiar than the alternative <strong>Perl-compatible preg family<\/strong>.<\/p>\n<p>Replacing  <strong>ereg()<\/strong>:<\/p>\n<pre>ereg('\\.([^\\.]*$)', $this-&gt;file_src_name, $extension);<\/pre>\n<p>becomes<\/p>\n<pre>preg_match('\/\\.([^\\.]*$)\/', $this-&gt;file_src_name, $extension);<\/pre>\n<p>Notice that I wrapped the pattern (<strong>\\.([^\\.]*$)<\/strong>) around <strong>\/ \/<\/strong>, which are RegExp delimiters. If you find yourself escaping <strong>\/<\/strong> too much (for an URL for example), you might want to use the <strong>#<\/strong> delimiter instead.<\/p>\n<p>Replacing <strong>ereg_replace()<\/strong>:<\/p>\n<pre>ereg_replace('[^A-Za-z0-9_]', '', $this-&gt;file_dst_name_body);<\/pre>\n<p>becomes<\/p>\n<pre>preg_replace('\/[^A-Za-z0-9_]\/', '', $this-&gt;file_dst_name_body);<\/pre>\n<p>Again, I just added delimiters to the pattern.<\/p>\n<p>If you are using <strong>eregi <\/strong> functions (which are the case-insensitive version of ereg), you\u2019ll notice there\u2019re no equivalent pregi functions. This is because this functionality is handled by <strong>RegExp modifiers<\/strong>.<\/p>\n<p>Basically, to make the pattern match characters in a case-insensitive way, append <strong>i<\/strong> after the delimiter:<\/p>\n<pre>eregi('\\.([^\\.]*$)', $this-&gt;file_src_name, $extension);<\/pre>\n<p>becomes<\/p>\n<pre>preg_match('\/\\.([^\\.]*$)\/i', $this-&gt;file_src_name, $extension);<\/pre>\n<p>Replacing  <strong>split()<\/strong>:<\/p>\n<pre>list($lat,$lng) = split(',', $coordinates);<\/pre>\n<p>becomes<\/p>\n<pre>list($lat,$lng) = preg_split('\/,\/',$coordinates);<\/pre>\n<p>you can also use <strong>explode()<\/strong> instead preg_list which will be available on PHP 6 :<\/p>\n<pre>list($lat,$lng) = explode(',',$coordinates);<\/pre>\n<p>Cheers,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you upgraded to PHP 5.3 like the famous oscommerce 2.2, chances are high you\u2019re going to run into a few warnings or deprecated function messages. An example is the ereg family of functions,&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2841,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,18],"tags":[159],"youtube_video":null,"_links":{"self":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/663"}],"collection":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=663"}],"version-history":[{"count":0,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/663\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2841"}],"wp:attachment":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}