PHP rtrim的问题

PHP rtrim的问题,php,string,substring,Php,String,Substring,对于上面的代码,我得到的输出是Andrew Langmoi。它也从字符串中删除了字符r。但是输出应该是Andrew Langmoir。这个问题只由字符r引起。请帮助 <?php $FacilitatorListStr = "Andrew Langmoir,<br/>"; $FacilitatorListStr = rtrim($FacilitatorListStr , ',<br/>'); echo $FacilitatorListS

对于上面的代码,我得到的输出是Andrew Langmoi。它也从字符串中删除了字符r。但是输出应该是Andrew Langmoir。这个问题只由字符r引起。请帮助

  <?php 

    $FacilitatorListStr = "Andrew Langmoir,<br/>";
    $FacilitatorListStr = rtrim($FacilitatorListStr , ',<br/>');
    echo $FacilitatorListStr;
    ?>
希望对你有用。

你可以这样试试

  <?php 

       $FacilitatorListStr = "Andrew Langmoir,<br/>";
       $FacilitatorListStr = substr($FacilitatorListStr,strpos($FacilitatorListStr,",")); 
       echo $FacilitatorListStr;

?>
编写代码:

在这种情况下,您可以使用str\u replace,如:

你可以在

此外,由于OP用于在末尾删除,请注意$character的用法,它表示字符串的结尾: 把它当作

<?php
    $FacilitatorListStr = str_replace(",<br/>","",$FacilitatorListStr );
    echo $FacilitatorListStr;
?>

另外,如果是用户输入字符串,那么use preg_quote first

看起来像是javascript与phpBecause混合在一起,因为你的掩码上有,所以如果这些字符中的任何一个出现在最后,它们都会被删除。在您的情况下,r是,在之后,r成为最后一个,因此被删除。如果有疑问:您还可以指定要删除的字符[…]。感谢@Prix解释try str_replace',',$FacilitatorListStr@Rakeshharma抱歉,我不认为我理解您的意思。感谢您的回复,但我需要删除字符串末尾的。还有其他方法吗?更新了答案,您可以在我提到的特定站点进行检查。谢谢:
<?php
    $FacilitatorListStr = str_replace(",<br/>","",$FacilitatorListStr );
    echo $FacilitatorListStr;
?>
    $FacilitatorListStr = preg_replace('/\,\<br\/\>$/', '',  $FacilitatorListStr);
    echo $FacilitatorListStr;