jair999 Posted October 7, 2010 Share Posted October 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
jair999 Posted October 7, 2010 Author Share Posted October 7, 2010 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? Quote Link to comment Share on other sites More sharing options...
chintansshah Posted October 7, 2010 Share Posted October 7, 2010 try to use HTML entities while you are displaying on the screen. Result Description Entity Name < less than < > greater than > & ampersand & Quote Link to comment Share on other sites More sharing options...
rwwd Posted October 7, 2010 Share Posted October 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
jair999 Posted October 7, 2010 Author Share Posted October 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.