Jump to content

php Novice struggling to read in a file... ;/


jair999

Recommended Posts

I'm trying to read in a file which is essentially a csv.  (I have a couple of books and am a n00b faffing with sessions/cookies etc and am trying to set up an app for a local forum I'm involved with...)

 

I originally tried fgetcsv and also reading the file in line by line (via fgets/explode) and for the most part it works.  However some of the entries have a '<' character within them and whenever the script hits a line with one of these it screws up and truncates the line.

 

I presume the '<' is attempting to redirect the data somewhere(?), but have found no way of being able to read this in whole as of yet and I dont really want to resort to processing each line character by character...

 

An example line would be:

 

3p!<ph4il,Fabulous Diamond Eyes,Lizzies,Div 3C

 

I welcome some advice to put me out of my misery on the matter :) 

Link to comment
https://forums.phpfreaks.com/topic/215312-php-novice-struggling-to-read-in-a-file/
Share on other sites

Upon further inspection, it appears the lines with '<' characters have indeed been read from the file into my array, but are not being echoed/printed to the web page...

 

A basic if test to determine if the '<' is contained within the yielded a success, so now all I have to figure is how to print the said lines to my web page :)

 

Any tips?

Could you post en excerpt of your code so that we can see exactly how your retrieving the data from the file, if this is a csv file, you can just use file() or file_get_contents() (the latter of which the manual says is the better choice) and then just use the comma as the way of putting everything into an array (explode()) or a string (implode()), there are a few ways to do this, but with out seeing your code first - it's just guesswork ;p

 

Rw 

Thx guys :)

 

Its 2am and I've finally traced what was happening...pretty obvious once the coffee kicked in.

 

Some of the strings that were being echo'd/print'ed contained: '<pxxxx' as parts of the strings. These combinations were included (in names of all things, not my idea...) and it was interpreting them as new <p> html statements.

 

echo "<p>Coach Name: ".htmlspecialchars($temp_Array[0],ENT_NOQUOTES); solved it (yes yes I will get round to using real Array names, this was for fault finding!) :))

 

I'm ripping the data from a csv file which has been created via Excel, with the intention of pre-filling out a mysql database.  Storing said entries in mysql may also pose some fun, but I'll worry about that tomorrow... :)

 

Much obliged all!

 

Jair

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.