-1

I have a problem with rtrim() function in php. I have string like this one:

$str = "<a id="AccountDocument_11" href="/view/id/11">Picture of Collateral</a> [2017-04-01],";

Like this, embed the string in array.
I want to remove that last comma in this string. rtrim not working.
When i remove that html elements from that string, rtrim() works perfectly. anyone help?

F0XS
  • 1,271
  • 3
  • 15
  • 19
SARAN
  • 127
  • 1
  • 3
  • 14
  • If rtrim isn't working, then it means that the comma isn't the last character in your string; do a var_dump() of the value to see what it contains – Mark Baker Oct 11 '17 at 12:04
  • This string should give syntax error – Jigar Shah Oct 11 '17 at 12:05
  • 2
    The string you provided is not properly escaped and when it is, it works OK with `rtrim()`. So, provide the string that isn't working. – mega6382 Oct 11 '17 at 12:07

3 Answers3

0

write your code below it works

you have write string ""(double quote) and under string you also used "" string instead of this you use ''(single quote);

<?php
$str = "<a id='AccountDocument_11' href='/view/id/11'>Picture of Collateral</a> [2017-04-01],";

echo rtrim($str,",");
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
0

i believe you quoted the string wrong.

try the below:

$str = rtrim('<a id="AccountDocument_11" href="/view/id/11">Picture of Collateral</a> [2017-04-01],',',');
echo $str;
Abdal Asif
  • 47
  • 13
0

you have to change your string like this, then it will work, it does not work because your string is inappropriate:

$str = "<a id='AccountDocument_11' href='/view/id/11'>Picture of 
Collateral</a> [2017-04-01],";
echo rtrim($str,",");

output is:

Picture of Collateral [2017-04-01]

The only difference is that double quoted strings interpret embedded variables and a number of escape sequences, while single quoted strings do not. E.g.:

Reference: When should you use single or double quotes in PHP?

Ahmad Hassan
  • 371
  • 4
  • 22