 {"id":49,"date":"2007-05-04T17:12:27","date_gmt":"2007-05-04T22:12:27","guid":{"rendered":"http:\/\/www.networkjack.info\/blog\/2007\/05\/04\/php-coding-fixing-old-code-for-new-standards\/"},"modified":"2007-05-04T17:14:14","modified_gmt":"2007-05-04T22:14:14","slug":"php-coding-fixing-old-code-for-new-standards-with-bbedit","status":"publish","type":"post","link":"http:\/\/www.networkjack.info\/blog\/2007\/05\/04\/php-coding-fixing-old-code-for-new-standards-with-bbedit\/","title":{"rendered":"PHP coding &#8211; fixing old code for new standards with BBEdit"},"content":{"rendered":"<p>We are trying very hard to move all our systems to PHP 5. This means going through lots of old code and correcting some bad habits.<\/p>\n<p>The biggest offender is the not quoting of references to keys in an associative array like so:<\/p>\n<blockquote><p>$Data[FirstName]<\/p><\/blockquote>\n<p>which should be:<\/p>\n<blockquote><p>$Data[&#8216;FirstName&#8217;]<\/p><\/blockquote>\n<p>so, I pulled out my favorite text munger, <a href=\"http:\/\/www.barebones.com\/products\/bbedit\/\" title=\"It Still Doesn't Suck\">BBEdit<\/a> and it&#8217;s excellent grep functionality and the ability to do searching over a directory. I ended up using this pattern:<\/p>\n<blockquote><p>\\[([a-zA-Z]+[_a-zA-Z0-9]+)\\]([^&#8221;&#8216;}])<\/p><\/blockquote>\n<p>This is looking for a left bracket, then any string that must start with an alpha character, then a right bracket. It&#8217;s also making sure there is NOT a quote or tick or right brace after that. The replacement pattern of:<\/p>\n<blockquote><p>[&#8216;\\1&#8217;]\\2<\/p><\/blockquote>\n<p>Now, this search picks up more than one would want, so it does take some effort to manually go through the results and do the replacement one by one. But I was able to take a medium to large code base and clean it up in about an hour.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are trying very hard to move all our systems to PHP 5. This means going through lots of old code and correcting some bad&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.networkjack.info\/blog\/2007\/05\/04\/php-coding-fixing-old-code-for-new-standards-with-bbedit\/\">Continue reading<span class=\"screen-reader-text\">PHP coding &#8211; fixing old code for new standards with BBEdit<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,13],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-text-munging","category-web-app-development","entry"],"_links":{"self":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/49"}],"collection":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":0,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}