Jump to content

Newbie help needed !


markjwrx

Recommended Posts

Hello

 

I am using the code below along with an XML file that contains all the data that the php below searches and suggests matching words and displays the text.

 

I am able to adjust the font of the outputted text by applying a class to the table.

 

This does not have any effect on the colour or decoration of the hyper link that is produced. I know need to add an <a class="links"> to the code some where and then apply a non decoration class but i just can't work out how to apply the html within the PHP.

 

I guess its needs to be added to the echo parts at the bottom ?

 

Many thanks in advance !

 

 

<?php
$xmlDoc=new DOMDocument();
$xmlDoc->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>0
if (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="<a href='" . 
       $z->item(0)->childNodes->item(0)->nodeValue . 
       "' target='_blank'>" . 
       $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
       }
     else
       {
       $hint=$hint . "<br /><a href='" . 
       $z->item(0)->childNodes->item(0)->nodeValue . 
       "' target='_blank'>" . 
       $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
       }
     }
   }
 }
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
 {
 $response="no suggestion";
 }
else
 {
 $response=$hint;
 }

//output the response
echo $response;
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...