Jump to content

Mystery null value? please help


Mojo5

Recommended Posts

Hi, I'm trying to get this text from a datafileto be able to be validated as json in a javascript after being sent from the server.

Here's the text:

[code]1;Jan;January;Janus;31;God of Doors This month opens the year.
2;Feb;February;februo;28;purify This was a Roman month of sacrifices and purification.
3;Mar;March;Mars;31;God of War Start of year for soldiers (no fighting during winter)
4;Apr;April;aperire;30;open This is the month when trees open their leaves.
5;May;May;Maia;31;Goddess of Growth This is the month when plants really start to grow.
6;Jun;June;Juno;30;Queen of the Gods
7;Jul;July;Julius;31;Caesar Ruler of Rome He reorganised the calendar.
8;Aug;August;Augustus;31;Ruler of Rome He thought he was at least as important as Julius Caesar!
9;Sep;September;septem;30;seven Seventh month (counting from March)
10;Oct;October;octo;31;eight Eighth month (counting from March)
11;Nov;November;novem;30;nine Ninth month (counting from March)
12;Dec;December;decem;31;ten Tenth month (counting from March)[/code]

here's the php:

[code]<?php
$info = file('data.txt');
foreach ($info as $line) {
$parts = split(";", $line);
$box = $parts[2];
$lid = $parts[4];
$jstr = '[\"$box\",$lid], ';
eval("\$jstr = \"$jstr\";");
eval("\$lid = \"$lid\";");
echo $jstr;
}
?> [/code]

and here's the result:

[code]["January",31], ["February",28], ["March",31], ["April",30], ["May",31], ["June",30], ["July",31], ["August",31], ["September",30], ["October",31], ["November",30], ["December",31], ["",], ["",], ["",],[/code]

I need to get rid of the last 3 null values, but I don't know why they're there to begin with. Any help would be great!

Thanks

Link to comment
https://forums.phpfreaks.com/topic/33564-mystery-null-value-please-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.