anevins Posted June 9, 2011 Share Posted June 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/ Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 instead of using $_SERVER['PHP_SELF'], which gives a relative path to the filename, perhaps you can try using __FILE__ which gives an absolute path to the page that is currently running the script. Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227410 Share on other sites More sharing options...
anevins Posted June 9, 2011 Author Share Posted June 9, 2011 $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) { } Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227417 Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 what errors do you receive when using $_SERVER['PHP_SELF']? Also, can you show the class that this call is coming form please Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227422 Share on other sites More sharing options...
anevins Posted June 9, 2011 Author Share Posted June 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227430 Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 the class that contains your loadHTMLFile() function that you are calling Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227451 Share on other sites More sharing options...
anevins Posted June 9, 2011 Author Share Posted June 9, 2011 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');?> Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227455 Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2011 Share Posted June 9, 2011 You want the name without the path, right? basename Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227470 Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 You want the name without the path, right? basename yes thats what was missing, anevins, you can use basename() with either$_SERVER['php_self'] or __FILE__ to return only the filename..e.g basename($_SERVER['PHP_SELF']) and basename(__FILE__) hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227479 Share on other sites More sharing options...
anevins Posted June 9, 2011 Author Share Posted June 9, 2011 thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/238871-php-dom/#findComment-1227487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.