如何在php变量/ xml doc / javascript变量中搜索

时间:2013-02-20 07:31:06

标签: php javascript xml xpath

我有一个名为xml的文件,标题中我有一个很长的描述。如何使用任何关键字进行搜索并获得匹配的整个字符串?例如,我在标题中有这个东西:

  

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

我希望它就像那样,如果我查询“lo”然后它应该返回所有匹配的可能性与lo(不仅是lo,整个字符串__>像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代码:

<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;
}}
?>

0 个答案:

没有答案