2、使用正则表达式preg_replace函数实现如下功能: 有一字符串变量:$str="PHP|

2、使用正则表达式preg_replace函数实现如下功能: 有一字符串变量:$str="PHP|s initialization 'file', generally called php.ini. is responsible for configuring many of the aspects of PHP's behavior." 要求你把其中的php或PHP单词后面紧跟的特殊符号(文中有| . '等三种)全部换成“#”,题目并不要求把语句的标点符号替换为#,注意替换条件看清楚再写正则表达式。最后文件保存为p2.php 请大神帮忙做一下这道题,实在不懂写
最新回答
安陵忻美

2024-09-07 00:34:55

php正则表达式:/(?<=PHP)[\||'|\.]/i

完整的php程序如下:

<?php

$str = "PHP|s initialization 'file', generally called php.ini. is responsible for  configuring many of the aspects of PHP's behavior."; 

$s = preg_replace("/(?<=PHP)[\||'|\.]/i","#", $str); 

echo $s;

?>

运行结果:

PHP#s initialization 'file', generally called php#ini. is responsible for  configuring many of the aspects of PHP#s behavior.