?php / * This will not work as expected. * / $num = 4; $string = "This string has four words ."; $string = ereg_replace('four', $num, $string); echo $string; / * Output: 'This string has words. '* / / * This will work. * / $num = '4'; $string = "This string has four words ."; $string = ereg_replace('four', $num, $string); echo $string; / * Output: 'This string has 4 words.' * /?
For example, the following code snippet prints "This was a test" three times: