Martin
Martin

Reputation: 35

How to Remove( " )Character from String

I want to remove ( " )Character from String. I tried str_replace,it work perfectly in some string and not working in below string,this shows error syntax error

$string = 'dfghhhhfgh 0201-228 8"X1" 'G' rgth fgh fgh';
echo str_replace('"','',$string);

I want to remove ( " )Character from this type String, I also tried preg_replace('/"/','',$string);

ltrim($string, '"');

is there any other solution?,Thanks

Upvotes: 0

Views: 77

Answers (1)

muted.spectre
muted.spectre

Reputation: 41

Php shows you a syntax error in this string because

$string = 'dfghhhhfgh 0201-228 8"X1" >>'G' rgth fgh fgh';

You close you string in this moment >>

In your case you need to use quote escaping:

$string = 'dfghhhhfgh 0201-228 8"X1" \'G\' rgth fgh fgh';

In this case your example works correctly.

Upvotes: 4

Related Questions