首页 > Web开发 > 详细

【PHP】ereg_repalce( )

时间:2017-09-30 10:50:53      阅读:227      评论:0      收藏:0      [点我收藏+]

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

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

【PHP】ereg_repalce( )

原文:http://www.cnblogs.com/Horsonce/p/7613868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!