5

What I'm trying to find out is which php function allows me to remove double quotes from the beginning and end of a text string if they exist

Musa Haidari
  • 2,109
  • 5
  • 30
  • 53
Jeff Davidson
  • 1,921
  • 7
  • 36
  • 60

2 Answers2

20

Use the trim function:

$str = '"Hello"';
echo trim($str, '"'); // Outputs Hello
Paul
  • 139,544
  • 27
  • 275
  • 264
  • So that will REMOVE quotes at the front and beginning of my text string? – Jeff Davidson Apr 21 '12 at 21:44
  • @user1333299 Yes, it will remove double quotes from the beginning and end, even if there are more than one, so `""""x""y"` would become `x""y` – Paul Apr 21 '12 at 21:50
  • What would be the opposite of that though. Like for example if I want to add them to the beginning and end of a text string? – Jeff Davidson Apr 21 '12 at 22:03
  • @user1333299 You can't undo it if you don't know how many quotes there were originally. You can add one quote to the begining and end thought like this: `$str = '"' . $str . '"';` – Paul Apr 21 '12 at 22:06
6

Trim is your friend:

trim($string,'"');
Nobita
  • 23,519
  • 11
  • 58
  • 87