Solved

PHP Regex - stripping quotes

Posted on 2013-05-15
3
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:Finec
ID: 39167591
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
ID: 39167620
try something like
$a =   "\"foo" ;
echo preg_replace("/^[\\\"]+(.+)[\\\"]$/", '${1}', $a);

Open in new window

HTH

Ivo Stoykov
0
 

Author Closing Comment

by:brothertom
ID: 39167640
Great, thanks very much...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

623 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