小编Sum*_*Rai的帖子

如何在PHP中从右修剪字符串?

我有一个字符串示例

this-is-the-example/exa
Run Code Online (Sandbox Code Playgroud)

我想从上面一行修剪/ exa

$string1 = "this-is-the-example/exa";
$string2 = "/exa";
Run Code Online (Sandbox Code Playgroud)

我在用 rtrim($string1, $sting2)

但是输出是 this-is-the-exampl

我想this-is-the-example作为输出。

这两个字符串都是动态的,并且在字符串中可能多次出现。但是我只想删除最后一部分。同样不是强制性的string2 /在其中。这也可能是正常的字符串。像aabc太..

php string trim

1
推荐指数
1
解决办法
465
查看次数

标签 统计

php ×1

string ×1

trim ×1