Page 1 of 1

Simple (hopefully) string parsing question.

Posted: Fri Aug 01, 2008 9:27 am
by Raybo58
I have a mySQL database full of data about our inventory.

One of the fields in the table I'm working with carries the dimensions of the item, expressed mainly in standard shorthand. Such as 3'6"x2'x6'4"

I often need to store the contents of this field somewhere while my code does other things.

The trouble I'm having is that any time I assign the data to anything other than a text element it strips off the last double quote, if there is one.

For instance, if I load the data directly from a recordset reference into a Select list element the data looks just as it should. But if I assign the data to a variable or pass it to POST or to Javascript it always removes the last double quote.

I've tried every combination of addlslashes(),stripslashes(), magic_quotes_gpc and magic_quotes_runtime that I can think of.

Through trial and error I found methods that make everything up to that last character work just fine. But that last double quote always turns up missing.

I suppose, if I have to, that I can do all the database stuff when the page is loaded and just leave it static. But I was really hoping to make it more dynamic if possible.

Re: Simple (hopefully) string parsing question.

Posted: Fri Aug 01, 2008 9:35 am
by jayshields

Re: Simple (hopefully) string parsing question.

Posted: Fri Aug 01, 2008 10:04 am
by Raybo58
Eeep!

Looks like that will do the trick. My research stopped just short of htmlentities(), If I'd only clicked one more link :)

Will let you know if it works in practice.

Re: Simple (hopefully) string parsing question.

Posted: Mon Aug 04, 2008 11:18 pm
by Raybo58
After about 30 more hours of head banging I finally got it to work.

htmlspecialchars() did turn out to be the answer.

It took me forever to figure out that the last double quote was being dropped BEFORE it was stored in $_POST. The only way to make it work was to turn on Magic Quotes in the .ini file.

Then it was being dropped again when I assigned the value of $_POST to a variable.

The answer turned out to be using htmlspecialchars() on the data before POST and then using htmlspecialchars_decode() to retrieve it from $_POST after the submit.

And of course I had to pepper the code with a great many addslashes() to have the values read correctly by other prodedures.

But it now works perfectly and I am very content :)