Pra*_*nku 1 php string substring
我想从结尾的字符串中删除字符串.
例如,我有一个PHP字符串变量"SomeText1|SomeText2|SomeText3|SomeText4|SomeText5|SomeText6",我想"SomeText1|SomeText2|SomeText3|SomeText4|SomeText5"在PHP中的值.
我尝试使用strrpos()以获得最后一次出现"|"我的索引现在我被困在如何进一步处理
每当我想要字符串排除最后一次出现的"|" 然后是文字.
如果你想要最后一个部分|:
$mystring = "SomeText1|SomeText2|SomeText3|SomeText4|SomeText5|SomeText6";
$strpos = strrpos($mystring, "|");
echo substr($mystring, $strpos);
Run Code Online (Sandbox Code Playgroud)
如果你想要在最后一个之前的第一部分|:
$mystring = "SomeText1|SomeText2|SomeText3|SomeText4|SomeText5|SomeText6";
$strpos = strrpos($mystring, "|");
$strlength = strlen(substr($mystring, $strpos));
echo substr($mystring, 0, -$strlength);
Run Code Online (Sandbox Code Playgroud)
功能参考:
1. http://php.net/manual/en/function.substr.php
2. http://php.net/manual/en/function.strrpos.php
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |