Jump to content

Parse data between tags and format it


eeeee

Recommended Posts

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:
[code]
###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###
[/code]

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  ???:
[code]<?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";

?>[/code]

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.