栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > PHP函数库

PHP - 函数:ereg_replace()

PHP函数库 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP - 函数:ereg_replace()

正则表达式函数库
ereg_replace

字符串比对解析并取代。

语法: string ereg_replace(string pattern, string replacement, string string);

返回值: 字符串

函数种类: 资料处理

内容说明

本函数以 pattern 的规则来解析比对字符串 string,欲取而代之的字符串为参数 replacement。返回值为字符串类型,为取代后的字符串结果。

使用范例

ken@freebsdrocks.com 在 16-Mar-1999 提出的例子。

?php
$text = 'This is a {1} day, not {2} and {3}.';
$daytype = array( 1 =  'fine',
 2 =  'overcast',
 3 =  'rainy' );
while (ereg ('{([0-9]+)}', $text, $regs)) {
 $found = $regs[1];
 $text = ereg_replace( { .$found. } , $daytype[$found], $text);
}
echo  $textn ;
// This is a fine day, not overcast and rainy. 
?

ken@freebsdrocks.com 并同时提出具有相同功能的perl 程序范例如下:

$text = 'This is a {1} day, not {2} and {3}.';
%daytype = ( 1 =  'fine',
 2 =  'overcast',
 3 =  'rainy' );
$text =~ s/{(d+)}/$daytype{$1}/eg;
print  $textn 参考

ereg()  eregi()  eregi_replace()  


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1493.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号