Jump to content

Live search help


rdrews

Recommended Posts

I'm trying to get live search set up for one of my pages and have been successful for the most part.  I basically used the code provided by w3schools (http://www.w3schools.com/php/php_ajax_livesearch.asp) but need to make a modification.  Their code is set up to read the link titles and urls from an xml file and search through the xml file but I would like to just search through a variable. 

 

So in the w3schools code there is this...

 

$xmlDoc=new DOMDocument();

$xmlDoc->load("links.xml");

$x=$xmlDoc->getElementsByTagName('link');

 

And I have this variable that I want it to search instead of "links.xml"...

$searchTest = "<pages><link><title>Search this text</title><url>www.gohere.com</url></link></pages>";

 

How do I get that into the $xmlDoc variable?  If I simply replace "links.xml" with $searchTest like this

 

$xmlDoc=new DOMDocument();

$xmlDoc->load($searchTest);

$x=$xmlDoc->getElementsByTagName('link');

 

I get nothing when I try to search.  But if I create a file in the php code and write the contents of $searchTest to that file then put that file in the $xmlDoc->load("newfile.xml"); line it searches and works fine.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/213937-live-search-help/
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.