Page 1 of 1

Silly question.

Posted: Tue Sep 23, 2008 10:34 am
by codec101
Trying to wipe the cobwebs from by head and make a php content control panel that basically reads a selected XML file, opens it, displays it, lets you make changes, add or remove an entry, yada yada.

That all works fine and well.

My problem is some of my data that it pulls from the xml file and sets to variables contains ', as in Steve's.

when displaying such a variable, i have no problems but when I set a default value for a form input textbox, as in when you edit a particular XML entry, it displays the current data as the default text in the text box before you change it, it cuts the string off when it gets to that ', as is Steve's. (it shows Steve in the textboxt, instead of Steve's bla bla bla).

my code is as such:

<input type='text' name='eventwhat' size = '65' value ='".$events_array[$eventid]->eventwhat."' />

for this instance, $events_array[$eventid]->eventwhat holds the string "Melissa's Marvelous Makeovers" and when displayed in the text box, i get Melissa, because of the '.

Is there a way I can get around that so the ' doesnt cut off the text in the textbox?

Re: Silly question.

Posted: Tue Sep 23, 2008 1:34 pm
by gethinw
You need to 'escape' the apostrophes, by adding a slash before them - this stops php treating them as the end of the string.

So, 'Steve's' becomes 'Steve\'s'. You can either do this manually or by doing addslashes($str) as required.

Re: Silly question.

Posted: Tue Sep 23, 2008 2:18 pm
by codec101
ok, well I cant do it manually as the XML file is read by the actuall website that is in flash, so It would have to be the addslashes($str).

I am not familar with that so I could do addslashes($events_array[$eventid]->eventwhat) and that would put slashes in as needed?

Re: Silly question.

Posted: Tue Sep 23, 2008 2:32 pm
by gethinw
Should do, try it out and see!