|
Question : Use ereg_replace to replace only the first occurence of a string instead of all?Answer :You can't do this with ereg_replace, but you can with preg_replace.
eg:
<?
$var = 'abcdef abcdef abcdef';
// pattern, replacement, string
echo ereg_replace('abc', '123', $var); // outputs '123def 123def 123def'
// pattern, replacement, string, limit
echo preg_replace('/abc/', '123', $var, 1); // outputs '123def abcdef abcdef'
?>
|