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
Asked
Active
Viewed 2.5k times
2 Answers
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