Link to home
Create AccountLog in
Avatar of brothertom
brothertom

asked on

PHP Regex - stripping quotes

Using something like preg_replace, it is possible strip quotes from both end of a string, but only if both quotes exists?

So,
$eg1 = "\"hello\""; results in hello
$eg2 = "goodbye\"" results in goodbye"
$eg3 = "yoo" results in yoo
$eg4 = "\"foo" results in "foo

Thanks
BT
Avatar of Finec
Finec
Flag of Hungary image

Hello,

Try to replace this with $1:
"([^"]*)"

Open in new window

If you don't allow spaces, use this:
"([^" ]*)"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of brothertom
brothertom

ASKER

Great, thanks very much...