PHP Problem

iEthan

Member
So, I've created a script that sees if a XML file with the same name is in pgs/. If it is, it will grab the title and put it in $title, and grab the content and put it in $content. Now, I need to get $name. I've defined it in the test page. But, it is giving me the error that it is an undefined variable. But, I have defined it.

Perhaps I should give you the code:

display.php (the script that grabs the content and title)
PHP:
<?php
if(file_exists('pgs/' . $name . '.xml')){
    $getXML = new DOMDocument();
    $getXML->load('pgs/' . $name . '.xml');
    
    $getPage = $getXML->getElementsByTagName("page");
    foreach($getPage as $page){
        $getTitle = $page->getElementsByTagName("title");
        $title = $getTitle->item(0)->nodeValue;
        
        $getContent = $page->getElementsByTagName("content");
        $content = $getContent->item(0)->nodeValue;
    }
}
?>

index.php (the test page)
HTML:
<?php
include('../display.php');
$name = 'index';
?>
<html>
    <head>
        <title>LiteManage Test</title>
    </head>
<body>
    <h1><?php echo $title ?></h1>
    <p><?php echo $content ?></p>
</body>
</html>

index.xml (the XML file that has the title and content.
Code:
<?xml version="1.0"?><page>    <title>Home</title>    <content>        Hello. My name is Ethan.    </content></page>

It is giving me the undefined error for $name, but it is clearly defined in index.php. How do I work around this?

You may need clarification...
 
Back
Top