Mojo5 Posted January 10, 2007 Share Posted January 10, 2007 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 More sharing options...
matto Posted January 10, 2007 Share Posted January 10, 2007 are there 3 line feeds in the bottom of the file......just a thought.... Link to comment https://forums.phpfreaks.com/topic/33564-mystery-null-value-please-help/#findComment-157171 Share on other sites More sharing options...
Mojo5 Posted January 10, 2007 Author Share Posted January 10, 2007 Sorry, what's a line feed? I haven't heard of that before.How do I get rid of it?Thanks for the response Link to comment https://forums.phpfreaks.com/topic/33564-mystery-null-value-please-help/#findComment-157175 Share on other sites More sharing options...
matto Posted January 10, 2007 Share Posted January 10, 2007 .....are there any blank lines at the end of the file you are reading? Link to comment https://forums.phpfreaks.com/topic/33564-mystery-null-value-please-help/#findComment-157197 Share on other sites More sharing options...
matto Posted January 10, 2007 Share Posted January 10, 2007 Give this ago[code]<?php$info = file('data.txt');foreach ($info as $line) { if(strpos($line,";")) { //line contains a delimiter $parts = split(";", $line); $jstr = "[\"$parts[2]\",$parts[4]],"; echo $jstr; }} ?>[/code] ;) Link to comment https://forums.phpfreaks.com/topic/33564-mystery-null-value-please-help/#findComment-157202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.