rdrews Posted September 20, 2010 Share Posted September 20, 2010 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 More sharing options...
Adam Posted September 20, 2010 Share Posted September 20, 2010 load() loads an XML file. You need to use loadXML() to load from a string. Link to comment https://forums.phpfreaks.com/topic/213937-live-search-help/#findComment-1113431 Share on other sites More sharing options...
rdrews Posted September 20, 2010 Author Share Posted September 20, 2010 load() loads an XML file. You need to use loadXML() to load from a string. Amazing, worked like a charm, thanks! Link to comment https://forums.phpfreaks.com/topic/213937-live-search-help/#findComment-1113433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.