Replacing a string using php
Simple code to replace a string using a very simple approach.
You can’t do this with ereg_replace, but you can with preg_replace.
<?
$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’
?>
Related posts:
