problem with perg_split
Posted: Mon Feb 07, 2011 1:58 pm
Hi,
I need help with this problem:
look at this code:
output:
When using PREG_SPLIT_DELIM_CAPTURE, if you use more than one pair of parentheses, the result array can have members representing all pairs. See array indexes 5 and 6 to see two adjacent delimiter results in which the second is a subset match of the first.
I can easily use this:
but what can I do if I cannot use the above code
for example:
then I cannot use this "?:"
so what can I do to hide index 6 of array
I need help with this problem:
look at this code:
Code: Select all
$s = '<p>bleh blah</p><p style="one">one two three</p>';
$htmlbits = preg_split('/(<p( style="[-:a-z0-9 ]+")?>|<\/p>)/i', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
print_r($htmlbits);
Code: Select all
Array
(
[0] =>
[1] => <p>
[2] => bleh blah
[3] => </p>
[4] =>
[5] => <p style="one">
[6] => style="one"
[7] => one two three
[8] => </p>
[9] =>
)
I can easily use this:
Code: Select all
$htmlbits = preg_split('/(<p(?: style="[-:a-z0-9 ]+")?>|<\/p>)/i', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
for example:
Code: Select all
$htmlbits = preg_split('/(<p(?=<f> style="[-:a-z0-9 ]+")?>|<\/p>)/i', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
so what can I do to hide index 6 of array