I have a mysql database which as one of the fields contains a html description. This description is not in my control, and is obtained and inserted automatically. An example of one of these descriptions is here:
http://www.nomorepasting.com/getpaste.php?pasteid=22492
The data is originally exported from an access database, and seems to remain intact. An example of the exported data is here:
http://www.yousendit.com/transfer.php?action=batch_download&batch_id=TTZtWmdsT01kMnVGa1E9PQ
I am trying to output the variable containing the html description into a popupwindow, to display it as is. The code I am trying to use to do this is here:
http://www.nomorepasting.com/getpaste.php?pasteid=22498
However it produces the following html code:
http://www.nomorepasting.com/getpaste.php?pasteid=22462
There is an unclosed style tag which prevents the rest of the page from displaying, and the popup winbdow from opening. I have narrowed this down to a php problem as far as I can tell, because the data seems fine in mysql.
edit:
I just attempted to select only article_Desc from the database with this code:
http://www.nomorepasting.com/getpaste.php?pasteid=22494
Which produced this as a result:
http://www.nomorepasting.com/getpaste.php?pasteid=22496
edit2:
There seem to be a problem with the countrycode variable containing the style tag. When I remove this, the picture is displayed and the popupwindow is created, only with html results much like the last link I pasted. The data seems correct in the database, so what could be causing this problem?
The CSV file is a bit of a mess. It appears that the fields are separated by tabs and not enclosed by anything. This may be OK for simple data but when you start putting HTML in you are going to have problems – looking at one of your other questions it looks like the CSV parser is getting confused and splitting one field of HTML into several – this seems to happen everytime it encounters a tab (and maybe also double quote?)
Are you able to change the format of the CSV file? I would suggest that you use commas to separate the fields, and that you define an enclosure character (e.g. a double quote) for more complex strings like HTML – I think that you will need to make sure that any double quotes within the string are also escaped. Also bear in mind that you may need to remove or escape line breaks from within these strings depending on what is parsing it, but I’m not completely sure of this.
Edit after your comment
You don’t need to worry about a string containing the delimiter, as long as it is enclosed by charactor. If you needed a row containing three fields, and the three string values were:
The following is not valid and would be seen by the parser as four fields
String1,String2,Stri,ng3The following is valid because the delimeter is ‘enclosed’ by a double-quote
'String1', 'String2', 'Stri,ng3'It gets trickier then when you want to have a double quote within the string – this would then need to be escaped. If you wanted to represent
the CSV field could be escaped like
If I remember correctly you were importing into MySQL using LOAD DATA?, so for the above examples you might want to use options like
I’m not sure how MySQL would treat line-breaks within enclosed strings, I can’t seem to find much about this. If it reads the file line-by-line you might need have problems.
Edit 2
If the remaining problems are line-break related you could do a string replace of
\nwith\\nand\rwith\\rin the code that exports each field to CSV