php中正則替換函數(shù)ereg_replace用法實例

字號:


    下面的實例是利用php 正則替換函數(shù) 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==========";