0

I have a xml file with a node named ,in title i have a long description. how to search using any keyword and get the whole string matched ? for example i have this thing in title :

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam magna sem, fringilla in, commodo a, rutrum ut, massa. Donec id nibh eu dui auctor tempor. Morbi laoreet eleifend dolor. Suspendisse pede odio, accumsan vitae, auctor non, suscipit at, ipsum. Cras varius sapien vel lectus"

and i want it to be like that if i query for "lo" then it should return all matching possibilities with lo (not only lo, the whole string__> like lorem)

source xml :

   <?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam magna sem, fringilla in, commodo a, rutrum ut, massa. Donec id nibh eu dui auctor tempor. Morbi laoreet eleifend dolor. Suspendisse pede odio, accumsan vitae, auctor non, suscipit at, ipsum. Cras varius sapien vel lectus</title>
  <genre>Computer</genre>
  <price>44.95</price>
  <publish_date>2000-10-01</publish_date>
  <description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>

Php code :

<form method="POST" id="searchform" action="">
<input type="text" name="search_text" id="search_text" />
<input type="submit" name="search"  id="search" />
</form>
<?php
$data = (array)simplexml_load_file('axx2.xml');
$data = array_pop($data);
if(isset($_POST['search']))
{
if($_POST['search_text']=="")
{
echo "please enter your search value";
exit;
}
}
if(isset($_POST['search'])){
$equalizing_value=$_POST['search_text'];
$no_of_data_in_xml=count($data);
for($i='0';$i<$no_of_data_in_xml;$i++)
{
$author=$data[$i]->author;
$title=$data[$i]->title;
$genre=$data[$i]->genre;
$description=$data[$i]->description;
}}
?>
Pranshu Jain
  • 570
  • 1
  • 7
  • 20
  • 2
    Do you have any examples of the source data and the current PHP code you have? – Mark Veenstra Feb 20 '13 at 08:04
  • This should be possible with SimpleXML/DOMDocument. Do you have an example of the XML file? I assume there are only certain elements you want to search against? – juco Feb 20 '13 at 08:44
  • Please properly indent your code. also make clear what does not work for you with your code, where do you hit the road-block exactly? Why does your example need a HTML form? Can't you simplify it? I bet you don't have a problem creating the HTML form, don't you? – hakre Feb 20 '13 at 09:48
  • actually i mentioned all things in the questions, i have to search for a string within that search box, form is for that, and i want to search for any string though this html form and want my matched search show as an output. that's it all. – Pranshu Jain Feb 20 '13 at 09:56
  • But your code is missing exactly that part. What have you written so far? What does not work when you write your code? Where is the *concrete* problem where you hit the roadblock? Otherwise, search when you look for ready-made code. – hakre Feb 20 '13 at 16:52

0 Answers0