Monday, 15 September 2014

regex - Mass replace deprecated functions in entire projects -



regex - Mass replace deprecated functions in entire projects -

i have bunch of php coded websites have been moved php 5.4 server , they're throwing deprecation warnings , errors.

is there way mass find & replace function names proper ones? example, able replace instances of session_unregister('somevar') unset($_session['somevar'])...

should utilize regex or there other way?

for particular illustration utilize sed this:

echo "session_unregister('somevar')" | sed 's/session_unregister(/unset\($_session[/;s/)/])/'

a bit more flexible utilize c preprocessor. assume php source file name my.php. add together extension .h becomes my.php.h. @ origin of file, insert:

#define session_unregister(x) unset($_session[x])

assume file contains lines in example: session_unregister('somevar')

run preprocessor this:

cc -e my.php.h

now should instead see unset($_session['somevar']) (plus garbage don't want).

note answers particular question, wouldn't recommend without more detailed testing.

regex

No comments:

Post a Comment