Jump to content

PHP DOM Troubles


TheJoey

Recommended Posts

<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("abc.xml");
echo '<form method="get">
search: <input type="text" name="search" /><br />
  <input type="submit" value="Submit" />
</form>';

// We need to validate our document before refering to the id
$xmldoc->validateOnParse = true;

function $id
{


}

$xmldoc->getElementByName('$id')->tagName . "\n";
print $xmlDoc->saveXML();
?> 

 

just now sure how to right a function that would search the xml file which contains.

<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books> 

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

<?php
$xmlDom = new DOMDocument();
$xmlDom->load("searchcontents.xml");


$xmldom->validateOnParse = true;

$variable =$argv[1];

$results =$xmlDom->getElementsByTagname($variable);
if $findresult = $variable
{
foreach ($findresults as $result) {
    // childNodes holds the result values
    $text_nodes = $result->childNodes;

    foreach ($text_nodes as $text) {
         print $text->nodeValue . "\n";
    }
}
}
print $xmlDom->saveXML();
?> 

 

ive changed my code to this but still cant get it to display all results that match

 

<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>PHP </title>
<publisher>booky</publisher>
</book>
</books> 

 

so if i try to search "jack" it will display all results with jack in it

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

Archived

This topic is now archived and is 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.