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
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?

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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

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.