The if (hint0) code for hint0 is defined as follows:
load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q) > 0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } else { $hint=$hint . "
item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == "") { $response="no suggestion"; }else { $response=$hint; } //output the responseecho $response;?>
In this code:
if ($hint=="") { $hint="item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } else { $hint=$hint . "
item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; }
Question 1: I have not defined $ hint = 0. why do I need if ($ hint = "")?
Question 2: for example, if $ hint is not 0, what is the code to be executed?
Reply to discussion (solution)
Where $ hint = 0?
The declaration $ hini = "" is used for storage. $ hini has no value during the first loop, but it will be available during the second loop.
Where $ hint = 0?
$ Hint = ""
Yes, it's not 0, but for convenience I say it's 0
$ Hint = ""; is defined outside of the for loop. when $ I = 0, $ hint is a null string and enters if ($ hint = "") the $ hint is no longer a null string when the judge is in progress but when the loop is added with 1, that is, when $ I = 1. this judgment is to distinguish the first loop.
$ Hint = ""; is defined outside of the for loop. when $ I = 0, $ hint is a null string and enters if ($ hint = "") the $ hint is no longer a null string when the judge is in progress but when the loop is added with 1, that is, when $ I = 1. this judgment is to distinguish the first loop.
Actually, you don't have to judge.
This is used to determine whether it is the first line. if it is not the first line, add
Line Feed
In fact, it is better to give a line feed to CSS without adding
, Which saves you the trouble of making such judgments.