Home > Backend Development > PHP Tutorial > 如何把未知长度的字符串从末尾截掉指定的字串呢?

如何把未知长度的字符串从末尾截掉指定的字串呢?

WBOY
Release: 2016-06-23 14:03:08
Original
839 people have browsed it

如:字串:沈阳市公安局电话 想截掉尾部的“电话”,如何实现呢?


回复讨论(解决方案)

preg_replace('/电话$/')
trim()
substr+strpos

楼上,能详细说下吗?比如s=沈阳市公安局电话 你提到的4个函数都得用上?

trim() http://www.w3school.com.cn/php/func_string_trim.asp
strpos() http://www.w3school.com.cn/php/func_string_stripos.asp
substr http://www.w3school.com.cn/php/func_string_substr.asp
perg_replace http://php.net/manual/en/function.preg-replace.php
请善用google

$s='沈阳市公安局电话';
echo preg_replace('/电话$/','',$s);

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template