首頁 >php教程 >php手册 >php中正则替换函数ereg_replace用法实例

php中正则替换函数ereg_replace用法实例

WBOY
WBOY原創
2016-06-13 09:18:361003瀏覽

php中正则替换函数ereg_replace用法实例

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

代码如下:

$num = 'www.jb51.net';
$string = "this string has four words.
";
$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**********

";
$string = ereg_replace ("^", "
", $string);
$string = ereg_replace ("$", "
", $string);
echo "==========$string==========";

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn