I am trying to grab a match of open tags. Having an issue where a parent tag is opened including a child tag. The parent tag is captured but it ignores the children tags.
ex.
</p>
<p>hello world</p>
<p><img
preg_match_all('/<(\/?[a-z]+)[^>]*\/?>/i', $trimmed_text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
would give the following output:
Array
(
[0] => Array
(
[0] => Array
开发者_C百科 (
[0] =>
[1] => 0
)
[1] => Array
(
[0] => /p
[1] => 1
)
)
[1] => Array
(
[0] => Array
(
[0] =>
[1] => 5 ) [1] => Array ( [0] => p [1] => 6 ) ) [2] => Array ( [0] => Array ( [0] =>
[1] => 19
)
[1] => Array
(
[0] => /p
[1] => 20
)
)
[3] => Array
(
[0] => Array
(
[0] =>
[1] => 24 ) [1] => Array ( [0] => p [1] => 25 ) ) )
Is it possible for any opened tags in a parent to have a subset array?
you're doing it the hard way, use PHP Simple HTML DOM Parser to parse html,
ex:
// Create DOM from URL or file
include('simple_html_dom.php');
$html = file_get_html('http://www.scroogle.org/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
精彩评论