Re: [PHP] extract escaped quoted strings



On Mar 29, 2008, at 4:16 PM, Adam Jacob Muller <php-general@xxxxxxx> wrote:

Hi,
Have a potentially interesting question here, wondering if anyone has done this one before and could shed some light for me.
I have a bit of PHP code that needs to extract some quoted strings, so, very simply:
"hello"
perfectly fine and works great
but, it should also be able to extract
"hel\"lo"
bit more complex now

Ideally, it would also handle
"hel\\"lo"
properly

it should also handle
"hel\\\"lo"


Any ideason how to do this? attempts to write a PCRE to do this are so-far unsuccessful, i'm sure I could badger some PHP code into doing it perhaps, but i'd love some elegant PCRE solution that thus- far evades me :(


Any ideas are appreciated.

-Adam


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


<?php
$string = "\"he\\\"llo\""; // "he\"llo"
$parsed = eval('return ' . $string . ';');
echo $parsed; // he"llo
?>
.



Relevant Pages

  • extract escaped quoted strings
    ... I have a bit of PHP code that needs to extract some quoted strings, so, very simply: ... attempts to write a PCRE to do this are so- far unsuccessful, i'm sure I could badger some PHP code into doing it perhaps, but i'd love some elegant PCRE solution that thus-far evades me:( ...
    (php.general)
  • Re: [PHP] extract escaped quoted strings
    ... So far a GREEDY pcre with quote on each end fits all the inputs. ... Whatever is causing that (MagicQuotes, cough, cough) is your REAL ... I have a bit of PHP code that needs to extract some quoted strings, ...
    (php.general)
  • Re: Newbie include question
    ... > I want to extract the connection string and put it in another file so I make a ... Whats the right way to put an include in PHP code? ... When you include something you get out of "php mode". ...
    (comp.lang.php)