Jump to content

Why I See Blank Page ?


Go to solution Solved by TheStudent2023,

Recommended Posts

Php Devs,

 

What is wrong with this code ? I see blank page.
Where did I go wrong on these two ?
Note where the $message variable is on both.

I get undefined $message if I leave it at the bottom. So, I tried rearranging to the 2 codes you see below.

1.

	// Initiate ability to manipulate the DOM and load that baby up
$doc = new DOMDocument();
libxml_use_internal_errors(true);
	// Because we are actually manipulating the DOM, DOMDocument will add complete <html><body> tags we need to strip out
//$message = str_replace(array('<body>', '</body>'), '', $doc->saveHTML($doc->getElementsByTagName('body')->item(0)));
$message = file_get_contents('https://www.rocktherankings.com/post-sitemap.xml');
	$doc->loadHTML($message, LIBXML_NOENT|LIBXML_COMPACT);
libxml_clear_errors();
	// Fetch all <a> tags
$links = $doc->getElementsByTagName('a');
	// If <a> tags exist ...
if ($links->length > 0)
{
    // For each <a> tag ...
    foreach ($links AS $link)
    {
        $link->setAttribute('class', 'link-style');
    }
}
	

 

2.

	// Initiate ability to manipulate the DOM and load that baby up
$doc = new DOMDocument();
	// Because we are actually manipulating the DOM, DOMDocument will add complete <html><body> tags we need to strip out
//$message = str_replace(array('<body>', '</body>'), '', $doc->saveHTML($doc->getElementsByTagName('body')->item(0)));
$message = file_get_contents('https://www.rocktherankings.com/post-sitemap.xml');
//$message = str_replace(array('<body>', '</body>'), '', $doc->saveHTML($doc->getElementsByTagName('body')->item(0)));
	libxml_use_internal_errors(true);
$doc->loadHTML($message, LIBXML_NOENT|LIBXML_COMPACT);
libxml_clear_errors();
	// Fetch all <a> tags
$links = $doc->getElementsByTagName('a');
	// If <a> tags exist ...
if ($links->length > 0)
{
    // For each <a> tag ...
    foreach ($links AS $link)
    {
        $link->setAttribute('class', 'link-style');
    }
}
	
Edited by TheStudent2023
Link to comment
https://forums.phpfreaks.com/topic/316242-why-i-see-blank-page/
Share on other sites

  • Solution

@ginerjm

Lol!

It is working now:

	ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
	//Sitemap Protocol: https://www.sitemaps.org/protocol.html
	// Initiate ability to manipulate the DOM and load that baby up
$doc = new DOMDocument();
	// Because we are actually manipulating the DOM, DOMDocument will add complete <html><body> tags we need to strip out
//$message = str_replace(array('<body>', '</body>'), '', $doc->saveHTML($doc->getElementsByTagName('body')->item(0)));
$message = file_get_contents('https://www.daniweb.com/programming/web-development/threads/538868/simplehtmldom-failing#post2288453');
	libxml_use_internal_errors(true);
$doc->loadHTML($message, LIBXML_NOENT|LIBXML_COMPACT);
libxml_clear_errors();
	// Fetch all <a> tags
$links = $doc->getElementsByTagName('a');
	// If <a> tags exist ...
if ($links->length > 0)
{
    // For each <a> tag ...
    foreach ($links AS $link)
    {
        $link->setAttribute('class', 'link-style');
    }
}
	$message = str_replace(array('<body>', '</body>'), '', $doc->saveHTML($doc->getElementsByTagName('body')->item(0)));
	

 

Edited by TheStudent2023

@ginerjm

 

But you keep saying RTFM. And so, I am. But stuck to find something. So care to help me find it ?

I can't find this particular line on the DomDocument Parser docs:

	$doc->loadHTML($message, LIBXML_NOENT|LIBXML_COMPACT); libxml_clear_errors();
	

The rest of the code, I found in the doc lastnight.
https://www.php.net/domdocument

And incase you are wondering how I manage to cook up the code, then answer is: I did not. Got it from somewhere.

1 hour ago, Barand said:

No. I am talking about this part, which me failing to find in the doc:

	.....IBXML_NOENT|LIBXML_COMPACT); libxml_clear_errors();
	

The error part.

Edited by TheStudent2023
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.