XPath and <script> tag with hidden script (<!-- -->)

Discussion in 'PHP' started by rustem, Nov 19, 2007.

  1. #1
    Most JavaScript scripts in pages are "hidden", i.e. they have <!-- before and ---> after the actual script text. When I try to use the following code:

    
    $html = new DOMDocument();
    
    @$html->loadHTMLFile($url); // fetch the remote HTML file and parse it
    $xml = simplexml_import_dom($html); // convert the DOM object to a SimpleXML object.
    
    //Parsing the JavaScript
    foreach ($xml->xpath('//script') as $node){
    	echo (string) $node;	
    }
    
    PHP:
    it only outputs the contents of the <script> tags, that do not have those comments in them. Is there any way to get the contents of those "hidden" scripts.

    Thanks for your help.
     
    rustem, Nov 19, 2007 IP