Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些字符串,一些以带有斜杠()的语言代码结尾"xx/",can be "fr/", or "en/", or other,一些以带有斜杠("int/", can be "2.0/" or "3.0/")的数字结尾。
"xx/",can be "fr/", or "en/", or other
"int/", can be "2.0/" or "3.0/"
如果字符串以“xx/”结尾,我想删除语言代码“xx/”,如果以“int/”结尾,则什么也不做。
通过substr($sring, -3),我可以确定什么是最终的。但是如果final是“xx/”怎么去掉呢?
substr($sring, -3)
$string = 'adfadsfasdfafasd asdf asdfasdf asdfr/'; $string = preg_replace('#[a-z]{2}/$#', '', $string); // case sensitive $string = preg_replace('#[a-z]{2}/$#i', '', $string); // case insensitive
未测试