I have this page test1.php on this other page test.php i have this php code running:
<?php
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile("http://inviatapenet.gethost.ro/sop/test1.php");
$xpath = new DOMXpath($doc);
$elements = $xpath->query("//*[@type='text/javascript']/@fid");
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue. "
";
}
}
}
?>
But shows nothing.
i'm trying to get from that page, only the content of fid="x8qfp3cvzbxng8e" :
From this Line
<script type="text/javascript"> fid="x8qfp3cvzbxng8e"; v_width=640;
v_height=360; </script>
The output shold be:
x8qfp3cvzbxng8e
Wath I have to do?
if you want only fid
content use this regex
preg_match_all('~fid="(.*?)"~si',$Text,$Match);
print_r($Match);
output for your sample
Array
(
[0] => Array
(
[0] => fid="x8qfp3cvzbxng8e"
)
[1] => Array
(
[0] => x8qfp3cvzbxng8e
)
)
try this for extract text this not show any script
content but if you want can remove condition of this
function extractText($node) {
if($node==NULL)return false;
if (XML_TEXT_NODE === $node->nodeType || XML_CDATA_SECTION_NODE === $node->nodeType) {
return $node->nodeValue;
} else if (XML_ELEMENT_NODE === $node->nodeType || XML_DOCUMENT_NODE === $node->nodeType || XML_DOCUMENT_FRAG_NODE === $node->nodeType) {
if ('script' === $node->nodeName) return '';
$text = '';
foreach($node->childNodes as $childNode) {
$text .= extractText($childNode);
}
return $text;
}
}
sample
$Text=file_get_contents("http://inviatapenet.gethost.ro/sop/test1.php");
preg_match_all('~fid="(.*?)"~si',$Text,$Match);
$fid=$Match[1][1];
echo $fid;