Home  >  Article  >  Backend Development  >  怎么把未知长度的字符串从末尾截掉指定的字串呢

怎么把未知长度的字符串从末尾截掉指定的字串呢

WBOY
WBOYOriginal
2016-06-13 11:17:45951browse

如何把未知长度的字符串从末尾截掉指定的字串呢?
如:字串:沈阳市公安局电话 想截掉尾部的“电话”,如何实现呢?

php字符串截取
------解决方案--------------------
$s='沈阳市公安局电话';
echo preg_replace('/电话$/','',$s);
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