This involves parsing the dom document.
<?php
function getTextBetweenTags($tag, $html)
{
$dom = new domDocument;
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$content = $dom->getElementsByTagname($tag);
$out = array();
foreach ($content as $item)
{
$out[] = $item->nodeValue;
}
return $out;
}
$xhtml = '<tag>abc def</tag><tag>123 456</tag>';
$content2 = getTextBetweenTags('tag', $xhtml);
foreach( $content2 as $item )
{
echo $item.'<br />';
}
?>
Output:
abc def
123 456
<?php
function getTextBetweenTags($tag, $html)
{
$dom = new domDocument;
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$content = $dom->getElementsByTagname($tag);
$out = array();
foreach ($content as $item)
{
$out[] = $item->nodeValue;
}
return $out;
}
$xhtml = '<tag>abc def</tag><tag>123 456</tag>';
$content2 = getTextBetweenTags('tag', $xhtml);
foreach( $content2 as $item )
{
echo $item.'<br />';
}
?>
Output:
abc def
123 456
How do i get content from URL with DIV tag?
ReplyDeleteBanTaySo.com
In php, you can use file_get_contents(URL);
ReplyDelete