What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP parsing certain lines of a text file

PHP parsing certain lines of a text file
Author: Message:
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: PHP parsing certain lines of a text file
you are either able to hard code that information, but if you want to make it dynamic, you can add another element to the text document...

method 1:

code:
<?php

$a = array('blue','white','black');

$c = file_get_contents('./ads.txt');
preg_match_all('/\s*"text"\s*"([^"]*)"/',$c,$m);
echo "<ol>";
for($i=0;$i<count($m[1]);$i++){
    echo "<li><span style='color:".$a[$i]."'>".$m[1][$i]."</span></li>";
}
echo "</ol>";

?>

method 2:

text document:

code:
"Advertisements"
{
    "1"
    {
        "type"        "S"
        "text"        "Ad1"
        "color"       "blue"
    }
    "2"
    {
        "type"        "S"
        "text"        "Ad2"
        "color"       "white"
    }
    "3"
    {
        "type"        "S"
        "text"        "Ad3"
        "color"       "black"
    }
}

php file:

code:
<?php

$c = file_get_contents('./ads.txt');
preg_match_all('/\s*"text"\s*"([^"]*)"/',$c,$m);
preg_match_all('/\s*"color"\s*"([^"]*)"/',$c,$a);
echo "<ol>";
for($i=0;$i<count($m[1]);$i++){
    echo "<li><span style='color:".$a[1][$i]."'>".$m[1][$i]."</span></li>";
}
echo "</ol>";

?>


hope this help [=
11-24-2009 12:32 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
PHP parsing certain lines of a text file - by Jimbo on 11-22-2009 at 07:13 PM
RE: PHP parsing certain lines of a text file - by John Anderton on 11-22-2009 at 07:22 PM
RE: PHP parsing certain lines of a text file - by prashker on 11-22-2009 at 07:59 PM
RE: PHP parsing certain lines of a text file - by Jimbo on 11-23-2009 at 12:07 AM
RE: PHP parsing certain lines of a text file - by NanaFreak on 11-23-2009 at 12:36 AM
RE: PHP parsing certain lines of a text file - by Jimbo on 11-23-2009 at 11:45 PM
RE: PHP parsing certain lines of a text file - by NanaFreak on 11-24-2009 at 12:32 AM
RE: PHP parsing certain lines of a text file - by Jimbo on 11-24-2009 at 08:03 AM
RE: PHP parsing certain lines of a text file - by NanaFreak on 11-24-2009 at 08:40 AM
RE: PHP parsing certain lines of a text file - by WDZ on 11-24-2009 at 09:05 AM
RE: PHP parsing certain lines of a text file - by Jimbo on 11-24-2009 at 03:22 PM
RE: PHP parsing certain lines of a text file - by NanaFreak on 11-25-2009 at 12:38 AM
RE: RE: PHP parsing certain lines of a text file - by Jimbo on 11-25-2009 at 07:57 AM
RE: PHP parsing certain lines of a text file - by John Anderton on 11-25-2009 at 06:29 AM
RE: PHP parsing certain lines of a text file - by NanaFreak on 11-25-2009 at 09:24 AM
RE: PHP parsing certain lines of a text file - by segosa on 12-14-2009 at 11:15 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On