是否有一个PHP字符串函数用于在特定字符后修整字符串。我看了一下php.net网站,做了一个谷歌搜索,但找不到任何东西。我能想到的唯一解决方案是爆炸,然后抓住阵列的第一部分,但这不是最优雅的解决方案。Php在特定字符处修剪字符串
例如
$string = "/gallery/image?a=b";
$string = imaginary_function($string,'?');
echo $string; //echoes "/gallery/image"
有谁知道一个好的小抄PHP的字符串处理函数的? 感谢
您可能会发现['s($ str) - > beforeFirst('?')'](https://github.com /delight-im/PHP-Str/blob/8fd0c608d5496d43adaa899642c1cce047e076dc/src/Str.php#L389)或['s($ str) - > beforeLast('?')'](https://github.com/delight- im/PHP-Str/blob/8fd0c608d5496d43adaa899642c1cce047e076dc/src/Str.php#L399)很有帮助,在[此独立库](https://github.com/delight-im/PHP-Str)中找到。 – caw