Solved

PHP Regex - stripping quotes

Posted on 2013-05-15
3
294 Views
Last Modified: 2013-05-15
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
0
Comment
Question by:brothertom
3 Comments
 
LVL 4

Expert Comment

by:Finec
Comment Utility
Hello,

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

Open in new window

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

Open in new window

0
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
Comment Utility
try something like
$a =   "\"foo" ;
echo preg_replace("/^[\\\"]+(.+)[\\\"]$/", '${1}', $a);

Open in new window

HTH

Ivo Stoykov
0
 

Author Closing Comment

by:brothertom
Comment Utility
Great, thanks very much...
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now