$str='abcdefg<span style="font-size:20px;">hijklmnop</span>qrs<span style="font-size:18px;color=F00;">tuv</span>wxyz';;
I would like to use php to make the above string as follows.
Array([0]=>abcdefg,[1]=>span style="font-size:20px;">hijklmnop</span>,[2]=>qrs,[3]=>span style="font-size="font-size:18px;color"
How can I resolve this?
php html array
If you don't think about nesting, you can use regular expressions.
$str='abcdefg<span style="font-size:20px;">hijklmnop</span>qrs<span style="font-size:18px;color=F00;">tuv</span>wxyz';;
preg_match_all('/(';[^>]+>[^>]+<\/[^>]+>|[^<]+')/',$str,$matches);
print_r($matches[1]);
As a regular expression concept,
This will give you the following results:
Array
(
[0] =>abcdefg
[1] =><span style="font-size: 20px;">hijklmnop</span>
[2] =>qrs
[3] =><span style="font-size: 18px;color=F00;">tuv</span>
[4] =>wxyz
)
If php deals with html like jquery, there is something called phpquery.
http://qiita.com/zaburo/items/465ca691aebad2b5691e
© 2024 OneMinuteCode. All rights reserved.