— tomauger.com

PHP Quickie: retrograding PHP const to pre-5.3

Oh, lately I’ve been having a blast accommodating web servers that are not running PHP 5.3+. Amongst other gotchas, you can’t use the handy class ‘const’ keyword to define constants, you must use define().

Anyway, here’s a quick RegExp you can use in your favorite text editor or IDE to search out all those oh-so-convenient ‘const’ declarations and replace them with their ugly cousin:

Search pattern:

\bconst\s+(\w+)\s+=\s+(['"])([^\\]*)\2;

Replace pattern:

define ('$1', '$3');

Happy RegExping!