Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 18,732 times

Related Categories

Replace only the first occurance in a string

altphpfaq

Although you can't do this with ereg_replace, you can use preg_replace instead:

<?
$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'
?>

Comments