萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php中正則替換函數ereg

php中正則替換函數ereg

 下面的實例是利用php 正則替換函數 ereg_replace來把指定的字符替換成我想需要的字符實例,代碼如下:

代碼如下: $num = 'www.jb51.net';
$string = "this string has four words. <br>";
$string = ereg_replace ('four', $num, $string);
echo $string;

 

$num = '49';
$string = "this string has four words";
$string = ereg_replace ('four', $num, $string);
echo $string;

$string ="測試用文字";
echo "**********$string**********<p>";
$string = ereg_replace ("^", "<br>", $string);
$string = ereg_replace ("$", "<br>", $string);
echo "==========$string==========";

copyright © 萬盛學電腦網 all rights reserved