#!/bin/bash
perl -p -i -e "s/eregi_replace *\\( *\"([^\@]+?)(?<\!\\\\)\", */preg_replace(\"\@\\1\@i\", /g" $1
perl -p -i -e "s/eregi_replace *\\( *\'([^\@]+?)(?<\!\\\\)\', */preg_replace(\'\@\\1\@i\', /g" $1
perl -p -i -e "s/ereg_replace *\\( *\"([^\@]+?)(?<\!\\\\)\", */preg_replace(\"\@\\1\@\", /g" $1
perl -p -i -e "s/ereg_replace *\\( *\'([^\@]+?)(?<\!\\\\)\', */preg_replace(\'\@\\1\@\', /g" $1
perl -p -i -e "s/eregi *\\( *\"([^\@]+?)(?<\!\\\\)\", */preg_match(\"\@\\1\@i\", /g" $1
perl -p -i -e "s/eregi *\\( *\'([^\@]+?)(?<\!\\\\)\', */preg_match(\'\@\\1\@i\', /g" $1
perl -p -i -e "s/ereg *\\( *\"([^\@]+?)(?<\!\\\\)\", */preg_match(\"\@\\1\@\", /g" $1
perl -p -i -e "s/ereg *\\( *\'([^\@]+?)(?<\!\\\\)\', */preg_match(\'\@\\1\@\', /g" $1
Here's a little bash script that I use. Someone with more time than me can probably squash all of this into less (1?) regular expressions, but it should do the trick. Feel free to replace @
with your delimiter of choice. Just paste this into a file, chmod +x
it, and then call it, passing the file as an argument.
If you need to use it en masse, something like this should suffice:
find /path/to/your/project -name '*.php' -exec foo {} \;
Where foo
is whatever you named the bash script.
Note: This isn't perfect, so you'll still need to manually change any fringe cases that it misses, but it will still save you a lot of work. Also note that this does in-place file edits.