Jump to content

search words in .xml file and save to DB


mehenky

Recommended Posts

Hello, i need some help/info about searching words in files (txt or xml) and saving them to db or another file.

 

For example ive got an xml file like below:

 

<families>

<family>

<name>brown</name>

<city>denver</city>

<members>12</members>

</family>

<family>

<name>jackson</name>

<city>new york</city>

<members>6</members>

</family>

</families>

 

i want to search for: <family> then save the lines till it comes to the word </family> and then goes to the next group. did some reading about array, preg_match, strpos functions but dont know where to start. what is the best way to do this?

 

can you guys give me some advise... or links to good tutorials?

 

thanks in advance!

Link to comment
Share on other sites

im following the basic steps in: http://uk3.php.net/manual/en/simplexml.examples-basic.php that is working good.

but now ive made this just to view:

<?php
$file = simplexml_load_file('stats.xml');
$check = new SimpleXMLElement($file);
echo $check->counts[0]->total;
?>

but im getting this error:
 

Warning: SimpleXMLElement::__construct(): Entity: line 16: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\simplexml.php on line 3

Warning: SimpleXMLElement::__construct(): in C:\xampp\htdocs\simplexml.php on line 3

Warning: SimpleXMLElement::__construct(): ^ in C:\xampp\htdocs\simplexml.php on line 3

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\simplexml.php:3 Stack trace: #0 C:\xampp\htdocs\simplexml.php(3): SimpleXMLElement->__construct('\n \n \n \n \n ...') #1 {main} thrown in C:\xampp\htdocs\simplexml.php on line 3


what is wrong with the code? below how the xml looks like.

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<stats>
<generated>140510</generated>
<u id="2">
<user>meh</user>
</u>
<counts>
<total>156715</total>
<online>
<now>125</now>
<today>1111</today>
<week>1576</week>
</online>
<registrations>
<today>206</today>
<week>505</week>
</registrations>
</counts>
</stats>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.