ltrim() and stripslashes() are not consistent

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
KimberCat
Forum Newbie
Posts: 3
Joined: Wed May 24, 2006 1:09 pm

ltrim() and stripslashes() are not consistent

Post by KimberCat »

Hi,

I have a php form that requests info from the user - some text boxes and a text area. The user can use an edit button to go back and edit his/her info before submitting the final form. Problem is that ltrim() does not work on all of the variables. I am still getting leading white spaces on some of the variables, while others aren't when the user uses the edit button to go back. I have checked my code carefully. Same thing going on with the stripslashes(). In some sections, it removes the "/" in front of apostrophes and in others, it doesn't.

Any suggestions?
Thanks, Kimber
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code.
KimberCat
Forum Newbie
Posts: 3
Joined: Wed May 24, 2006 1:09 pm

ltrim() & stripslashes() not being consistent

Post by KimberCat »

Code: Select all

<input type="hidden" name="firstName" value=" <? $firstName = ltrim($firstName); print stripslashes($firstName) ?> ">
<input type="hidden" name="lastName" value="<? $lastName = ltrim($lastName); print stripslashes($lastName) ?> ">

<strong><div style="margin-right: 150px"><? $message=ltrim($message);  print stripslashes($message); ?></div></strong>
In the above snippet of code, when the user clicks on the edit button and goes back to edit the form, the last name does NOT get any leading white space inserted before it in the text box, but the first name does.

The message gets indented and broken up over numerous lines when printed out in the text area, if the user goes back to edit their info. It is also escaping any apostrophes that the user might enter in their message. If the user goes back more than once, it is a real mess. However going from the form to the confirm screen, it does NOT escape anything and behaves quite nicely. My problems are going backward to edit the original info. AAUGH.

Any help would be greatly appreciated.

Thanks, Kimber
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the value of firstName has space around the printed text.

As for the "textarea" it's hard to say since you didn't post more code..
penpaper
Forum Newbie
Posts: 15
Joined: Tue May 23, 2006 6:45 pm
Location: Coudersport, PA, USA

leading spaces & escaped apostrophes

Post by penpaper »

Thanks for pointing out the spaces in the code. They are gone now.

The code used for the textarea in the file that the user posts to an email:

Code: Select all

<strong><div style="margin-right: 150px"><? $message=ltrim($message);  
	$message=htmlspecialchars($message, ENT_QUOTES); print stripslashes($message); ?></div></strong>
This code makes for very pretty stuff when printed to screen. However, the spaces (looks like multiple tabs and hard breaks) show up when printed in a textarea.

Code: Select all

<textarea id="message" name="message" wrap="hard" cols=70 
rows=10 width="120" onKeyDown="textCounter(this.form.message,this.form.remLen,480);" 
onKeyUp="textCounter(this.form.message,this.form.remLen,480);">
			<?php   $message = ltrim($message); print stripslashes($message); ?></textarea>
When the user is satisfied with their input the form is submitted to an email which is great except for the spaces and the ENT_QUOTES prints out the ' where the apostrophe would have been and the escape backslash is there also?!????.

thanks for your help! lauren
penpaper
Forum Newbie
Posts: 15
Joined: Tue May 23, 2006 6:45 pm
Location: Coudersport, PA, USA

Post by penpaper »

OK! I figured it out. I had spaces in my coding again. I now know about spaces in coding. A valuable lesson that came to me way too slowly. Thank you for your patients.

lauren
Post Reply