[Phpmyadmin-devel] preg vs. ereg

Ignacio Vazquez-Abrams ignacio at openservices.net
Sat Aug 18 22:08:05 CEST 2001

On Sat, 18 Aug 2001, Robin Johnson wrote:

> Ok, looking under 'Support Requests' (#447076) there is a note about using
> ereg instead of preg, so i went back to convert my lone instance of a preg
> in the code.
> But try as hard as I might, I can't manage to use eregi_replace to do the
> same thing as my bit of code.
> lib.inc.php3 - line 694
> $sql = preg_replace(
> 	'/\W'.$data[1].'\./i',
> 	' '.$data[0].'.',
> 	$sql);
> Could somebody else make a suggestion about the query I can use?
> my best conversion of the pcre was "[!a-zA-Z0-9_]".$data[1]."\." but that
> doesn't work :-(.
> I have also realized that my code adds a nasty little bug.
> this is the SQL i was using to test the above:
> SELECT c.id, s.id FROM classes c, staff s WHERE c.staff = s.id ORDER BY
> s.id
> now if i change the fields section at the start just slightly, and the
> where clause by taking out some of the white space:
> SELECT c.id,s.id FROM classes c, staff s WHERE c.staff=s.id ORDER BY s.id
> then the ',' in the fields gets replaced with a space, and your perfectly
> valid query is now invalid. The same thing happens with the '=' in the
> where clause. We need to find a way to preserve the other character that
> matched the \W in the pcre as well as add a space after it. I had the \W
> in there so that trying to match 's.' would not match 'foods.' . Any
> suggestions on this one?

Does this work?

  $sql=eregi_replace('([^a-zA-Z0-9])'.$data[1].'\.', '\1 '.$data[0].'.',

Ignacio Vazquez-Abrams  <ignacio at openservices.net>

More information about the Developers mailing list