Jump to content


Photo

Parse data between tags and format it


  • Please log in to reply
No replies to this topic

#1 eeeee

eeeee
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 September 2006 - 02:06 AM

Just registered here, so: "Hello to all!"

I started learning PHP 3 days ago, because i need it to solve my problem. Because of my slow progres i was hoping someone here might be able to help me...

My data is in a large file, here is a short example:
###x###x###x###x###
<img [LOGO]logo.jpg[/LOGO]
</a><a href="javascript:void(0);" onClick="openPop_new('index.php@dep_id=1&layout=112&picture_id=483', 'picture', 100, 100, '');"><img src="images/icon_zoom_small.gif" width="10" height="10" border="0"></a>
[NAME]WTF[/NAME]
<img src="images/11/icon_new_window.gif" border="0" align="absmiddle" /></a>
<a target="_blank" href="index.php@dep_id=1&layout=71&subject=152"><img src="images/11/icon_print_s.gif" border="0" align="absmiddle" /></a>
<a href="[EMAIL]info@wtf.com[/EMAIL]
[ADDRS]xxx 3 [/ADDRS][OB]1000[/OB]
###y###y###y###y###

The data for one of many clients is between ###x###x###x###x### and ###y###y###y###y###
Information for one client is between tags like [NAME]bla[/NAME], [ADDRS], [OB],...
Not all clients have all of these tags.

I would like to my php script to output just:
1;logo.jpg;WTF;info@wtf.com;xxx 3;1000
(1 - number of client, which is incremented, the rest is text between tags[LOGO],[NAME],[EMAIL])

If some tags do not exist between ###x###x###x###x### and ###y###y###y###y###, their value should be "0".
Example: If the [LOGO][/LOGO] tag wouldnt exist, the output would be:
1;0;WTF;info@wtf.com;xxx 3;1000
--------
My code so far  ???:
<?php

$file = file_get_contents('data.txt');

preg_match("/\[NAME\](.+?)\[\/NAME\]/", $file, $nameX);
$name = $nameX[1];

preg_match("/\[ADDRS\](.+?)\[\/ADDRS\]/", $file, $addrsX);
$addrs = $addrsX[1];


echo "$name; $addrs";

?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users