Jump to content

Recommended Posts

I want to load the current page dynamically,

instead of:

$dom->loadHTMLFile('index.php');

 

I can't use

$_SERVER["PHP_SELF"]

or

$_SERVER["SCRIPT_NAME"]

as they both give values of a string with a directory, rather than the file.

 

For example, if used

$dom->loadHTMLFile('$_SERVER["PHP_SELF"]');

 

The string passed to function is that it is trying to load is:

/xampp/portfolio/gallery.php

 

Is there any way I can pick off the gallery.php and not the rest of the string?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/238871-php-dom/
Share on other sites

$dom->loadHTMLFile(__FILE__);

 

I get warnings:

 

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: error parsing attribute name in file:///D:/xampp/xampp/htdocs/xampp/portfolio/php/navigation.php, line: 15 in D:\xampp\xampp\htdocs\xampp\portfolio\php\navigation.php on line 4

 

and $dom vardumped is object(DOMDocument)#1 (0) { }

Link to comment
https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227417
Share on other sites

When using PHP_SELF I get the errors:

 

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity "/xampp/portfolio/index.php" in D:\xampp\xampp\htdocs\xampp\portfolio\php\navigation.php on line 4

 

Fatal error: Call to a member function getAttribute() on a non-object in D:\xampp\xampp\htdocs\xampp\portfolio\php\navigation.php on line 6

 

I'm not sure what you mean by "can you show the class..." sorry.

 

Link to comment
https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227430
Share on other sites

navigation.php

<?php
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadHTMLFile($_SERVER['PHP_SELF']);
$body = $dom->getElementsByTagName('body');
$id= $body->item(0)->getAttribute('id'); // home


?>

<div id="header">
<div id="logo">
	<a href="index.php"><img src="images/nevins.png" alt="NEVINS Web Design" /></a>
</div>
<ul id="navigation">
	<li <?php if ($id=='home') echo 'class="selected"';?>><a href="index.php">Welcome</a></li>
	<li>|</li>
	<li <?php if ($id=='gallery') echo 'class="selected"';?>><a href="gallery.php">Gallery  </a></li>
	<li>|</li>
	<li><?php if ($id=='contact') echo 'class="selected"';?><a href="contact.php">Contact</a></li>
</ul>
</div>

 

index.php:

<?php 
include_once('php/header.php');
?>

<body id="home">

<script type="text/javascript">
Cufon.replace('h1');
Cufon.replace('#navigation a' ,{ hover: true,  fontFamily: 'Josefin Sans Std'});	

</script>  
<?php include_once('php/navigation.php');?>

 

Link to comment
https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227455
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.