【PHP】ereg_replace( )

ereg_replace — 正则表达式替换

string ereg_replace ( string $pattern , string $replacement , string $string )

代码:

<?php
    $num="4";
    $string="this was four cats";    
    $str=ereg_replace('()was','\\1is', $string);
    $str1=str_replace('was','is',$string);
    $str2=ereg_replace('four',$num, $string);
    echo $str.'<br>';
    echo $str1.'<br>';
    echo $str2.'<br>';    
?>

输出结果:

this is four cats
this is four cats
this was 4 cats

括号可以嵌套,此情形下以左圆括号来计算顺序。

posted on 2017-09-30 10:13  忆华灯纵博  阅读(193)  评论(0编辑  收藏  举报