You are here: Re: $_POST adding whitespace to variable value « PHP Programming Language « IT news, forums, messages
Re: $_POST adding whitespace to variable value

Posted by Good Man on 11/12/81 12:00

"Mason Barge" <masonbarge@comcast.net> wrote in
news:NfidnfLSQ8PTQhHanZ2dnUVZ_hOdnZ2d@comcast.com:

> I have a standard POST form consisting of two types of input: text
> input and textarea. The form downloads current settings from a mysql
> database. The user can update the information by modifying the text
> and clicking a standard "submit" button.
>
> MAIN PROBLEM:
>
> My problem is that the information transmitted to the formhandler
> apparently has some sort of whitespace added to it. If I simply use
> trim() on the POST variable, it fails the regex.

No it doesn't. You are confused about what a post variable is. You
can't change what's been $_POSTed, but you can certainly ASSIGN the
value to your own variable and change *that*.

> If I convert to POST
> variable to a single variable and use trim(), it solves the problem.

As explained above.


> I can just convert and trim every variable, but it would be a lot
> cleaner to trim the entire POST array with a foreach(). Plus, I'd much
> rather understand the problem. In other words:
>
> This code works:
> $zip=trim($_POST['zip']);
> if (preg_match("/^[\d]{5}/", $zip)) {
> $update.=" zip='$zip',";
> } else {
> error_alert('Zip code must be exactly 5 digits with no other
> characters. '); }
>
> This code throws a regex rejection:
>
> $_POST['zip']=trim($_POST['zip']);

as hinted at above - what are you doing here? why are you trying to
*set* a $_POST variable, which has a very specific meaning? Why are you
using this code at all, as opposed to the code above which does what you
want in the correct way???

Are you trying to trim the $_POST elements in one fail swoop? Well you
can either use array_map to apply a trim-type function to the $_POST
array, but be aware that it will mess up any $_POST elements which are
arrays themselves (unless you use one of the user contributions on the
manual page). Personally, I specifically trim every $_POST'ed element.


> Of course, my real problem is how the whitespace gets in there in the
> first place.

Nope, who cares how it got in?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация