Find actual value of PHP variable

Posted by Simon S on Stack Overflow See other posts from Stack Overflow or by Simon S
Published on 2010-05-03T13:14:55Z Indexed on 2010/05/03 13:18 UTC
Read the original article Hit count: 369

Filed under:
|
|

Hi all. I am having a real headache with reading in a tab delimited text file and inserting it into a MySQL Database.

The tab delimited text file was generated (I think) from a MS SQL Database, and I have written a simple script to read in the file and insert it into an existing table in my MySQL database.

However, there seems to be some problem with the data in the txt file. When my PHP script parses the file and I output the INSERT statements, the values in each of the fields are longer than they should be. For example, the first field should be a simple two character alphanumeric value. If I echo out the INSERT statements, using Firebug (in Firefox), between each of the characters is a question mark in a black diamond. If I var_dump the values, I get the following:

string(5) "A1" 

Now, this clearly shows a two character string, but var_dump tells me it is five characters long!!

If I trim() the value, all I get is the first character (in this case "A").

How can I get at the other characters, even if it is only to remove them? Additionally, this appears to be forcing MySQL to insert the value as a BLOB, not as a varchar as it should.

Simon

© Stack Overflow or respective owner

Related posts about php

Related posts about variable