Ho scritto queste funzioni che sostituiscono le funzioni ereg mantenendo la stessa sintassi:
<?php
/**
* define php standard functions
*
* @author Alessandro Vernassa
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License
*/
if (! function_exists ( 'ereg' ))
{
function ereg($find, $str, &$regs)
{
return fn_erg ( $find, $str, $regs );
}
}
if (! function_exists ( 'eregi' ))
{
function eregi($find, $str, &$regs)
{
return fn_ergi ( $find, $str, $regs );
}
}
if (! function_exists ( 'ereg_replace' ))
{
function ereg_replace($pattern, $replacement, $string)
{
return fn_erg_replace ( $pattern, $replacement, $string );
}
}
if (! function_exists ( 'eregi_replace' ))
{
function eregi_replace($pattern, $replacement, $string)
{
return fn_ergi_replace ( $pattern, $replacement, $string );
}
}
function fn_erg($find, $str, $regs=null)
{
return preg_match ( "/" . str_replace ( '/', '\\/', $find ) . "/s", $str, $regs );
}
function fn_ergi($find, $str, $regs=null)
{
return (preg_match ( "/" . str_replace ( '/', '\\/', $find ) . "/si", $str, $regs ));
}
function fn_erg_replace($pattern, $replacement, $string)
{
return preg_replace ( "/" . str_replace ( '/', '\\/', $pattern ) . "/s", $replacement, $string );
}
function fn_ergi_replace($pattern, $replacement, $string)
{
return preg_replace ( "/" . str_replace ( '/', '\\/', $pattern ) . "/si", $replacement, $string );
}
?>
le uso da un po' e sono abbastanza collaudate.
Ho messo volutamente il nome "erg" invece che "ereg" in modo che si possa fare un trova/sostituisci di "ereg" su tutti i files di eventuali programmi già scritti senza che vengano sovrascritte le nuove funzioni.
Alex