php 正则替换函数 ereg_replace

下面的实例是利用php 正则替换函数 ereg_replace来把指定的字符替换成我想需要的字符实例,代码如下:

  1. $num = 'www.phpfensi.com';
  2. $string = "this string has four words. <br>";
  3. $string = ereg_replace ('four', $num, $string);
  4. echo $string;
  5. $num = '49';
  6. $string = "this string has four words";
  7. $string = ereg_replace ('four', $num, $string);
  8. echo $string;
  9. $string ="测试用文字";
  10. echo "**********$string**********<p>";
  11. $string = ereg_replace ("^", "<br>", $string);
  12. $string = ereg_replace ("$", "<br>", $string);
  13. echo "==========$string==========";
  14. //开源代码phpfensi.com