Silly question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
codec101
Forum Newbie
Posts: 2
Joined: Tue Sep 23, 2008 10:21 am

Silly question.

Post 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?
gethinw
Forum Newbie
Posts: 16
Joined: Tue Sep 23, 2008 4:02 am

Re: Silly question.

Post 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.
codec101
Forum Newbie
Posts: 2
Joined: Tue Sep 23, 2008 10:21 am

Re: Silly question.

Post 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?
gethinw
Forum Newbie
Posts: 16
Joined: Tue Sep 23, 2008 4:02 am

Re: Silly question.

Post by gethinw »

Should do, try it out and see!
Post Reply