Home >Backend Development >PHP Tutorial > preg_replace匹配的正则表达式

preg_replace匹配的正则表达式

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:54:59924browse

求一个preg_replace匹配的正则表达式
用PHP ,preg_replace函数匹配一个正则 

字符串为"house and market and "
替换掉最后一个and,要输出结果为"house and market "

试了半天没写出来,谢谢各位大侠给个匹配的正则


------解决方案--------------------
$str = "house and market and ";
$str = preg_replace('/and(\s*)$/', '', $str);
var_dump($str);
?>
如何。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn