PHP DOMDocument not working
Posted by: Fiskan (---.12-4.cable.virginm.net)
Date: August 30, 2014 03:43AM

Version of Operating system? - 64bit
Version of Wamp Server installed? - 64bit
Version of Apache you are running? 2.4.9
Version of MySQL you are running? 5.6.17
Version of PHP you are running? 5.5.12
------------------------------------

Here's a sample code:

index.php

<?php

$site = new domDocument();
$div = $site->createElement("div" );

$class = $site->createAttribute("class" ) ;
$class->nodeValue = "wrapper";

$div->appendChild($class);

$site->appendChild($div);

$html = $site->saveHTML();

?>

I run this on chrome and I expect something like <div class="wrapper"></div> but there is no such div. I tried googling for solutions but none has solved my problem so far. What could be the problem? Should I reinstall wampserver?



Edited 1 time(s). Last edit at 08/30/2014 04:28AM by Fiskan.

Options: ReplyQuote
Re: PHP DOMDocument not working
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: August 31, 2014 02:49PM

It is not necessary to reinstall WAMPServer!

Why are you using DOMDocument? Just do


<div class="wrapper"></div>

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: PHP DOMDocument not working
Posted by: Fiskan (---.12-4.cable.virginm.net)
Date: August 31, 2014 09:13PM

I need DOMDocument to do some website scraping through PHP. See this video: [www.youtube.com]

Options: ReplyQuote
Re: PHP DOMDocument not working
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: August 31, 2014 09:25PM

You use DomDocument when processing some web page that you decide to scrape and not to build your own pages.

EG

$xml = new DOMDocument();

// Load the url's contents into the DOM 

$xml->loadHTMLFile('http://www.google.com');

// Empty array to hold all links to return 
$links = array();

//Loop through each <a> tag in the dom and add it to the link array 
foreach ($xml->getElementsByTagName('a') as $link) {
    $url = $link->getAttribute('href');
    if (!empty($url)) {
        $links[] = $link->getAttribute('href');
     }
}

print_r($links);

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.