like for example, i want to be able to match the attribute values for ALL of the tags in my example.
my problem is, i need to start the match w/ either
attribute="
or
attribute='
but then i need the regex to remember whether it started w/ a double or single quote, and use that as the ending delimiter.
i made a pattern but obviously it wont work if the value is something like
attribute="foo's"
because im trying to capture foo's not just foo
Code: Select all
<?php
$subject = '
<tag attribute="value">
<tag attribute="foo''s">
<tag attribute="a ''value'' with quotes">
<tag attribute=''another "value" with """quotes''>
';
$pattern = '/attribute=(''|")([^''"]*)(''|")/i';
preg_match_all($pattern, $subject, $matches);
?>so its like i need to capture which character i matched in the first parenthesis, then use that character again in the second and third parenthesis. i just dont know how.
the results im trying to acheive from the above $subject are as follows
Code: Select all
value
foo's
a 'value' with quotes
another "value" with """quotesany direction you could give me is appreciated