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