rtrim 不适用于包含 html 元素的字符串
rtrim not working string with html elements
我对 php 中的 rtrim()
函数有疑问。我有这样的字符串:
$str = "<a id="AccountDocument_11" href="/view/id/11">Picture of Collateral</a> [2017-04-01],";
像这样,将字符串嵌入到数组中。
我想删除该字符串中的最后一个逗号。 rtrim 不工作。
当我从该字符串中删除 html 元素时,rtrim()
完美运行。有人帮忙吗?
在它下面写下你的代码
你写了 string ""(double quote)
并且在 string
下你还使用了 "" 字符串而不是你使用 ''(single quote);
<?php
$str = "<a id='AccountDocument_11' href='/view/id/11'>Picture of Collateral</a> [2017-04-01],";
echo rtrim($str,",");
我相信你引用的字符串有误。
尝试以下操作:
$str = rtrim('<a id="AccountDocument_11" href="/view/id/11">Picture of Collateral</a> [2017-04-01],',',');
echo $str;
你必须像这样更改你的字符串,然后它才会起作用,它不起作用,因为你的字符串不合适:
$str = "<a id='AccountDocument_11' href='/view/id/11'>Picture of
Collateral</a> [2017-04-01],";
echo rtrim($str,",");
输出为:
Picture of Collateral [2017-04-01]
唯一的区别是双引号字符串会解释嵌入变量和一些转义序列,而单引号字符串则不会。例如:
参考:When should you use single or double quotes in PHP?
我对 php 中的 rtrim()
函数有疑问。我有这样的字符串:
$str = "<a id="AccountDocument_11" href="/view/id/11">Picture of Collateral</a> [2017-04-01],";
像这样,将字符串嵌入到数组中。
我想删除该字符串中的最后一个逗号。 rtrim 不工作。
当我从该字符串中删除 html 元素时,rtrim()
完美运行。有人帮忙吗?
在它下面写下你的代码
你写了 string ""(double quote)
并且在 string
下你还使用了 "" 字符串而不是你使用 ''(single quote);
<?php
$str = "<a id='AccountDocument_11' href='/view/id/11'>Picture of Collateral</a> [2017-04-01],";
echo rtrim($str,",");
我相信你引用的字符串有误。
尝试以下操作:
$str = rtrim('<a id="AccountDocument_11" href="/view/id/11">Picture of Collateral</a> [2017-04-01],',',');
echo $str;
你必须像这样更改你的字符串,然后它才会起作用,它不起作用,因为你的字符串不合适:
$str = "<a id='AccountDocument_11' href='/view/id/11'>Picture of
Collateral</a> [2017-04-01],";
echo rtrim($str,",");
输出为:
Picture of Collateral [2017-04-01]
唯一的区别是双引号字符串会解释嵌入变量和一些转义序列,而单引号字符串则不会。例如:
参考:When should you use single or double quotes in PHP?