Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting rid of '

Status
Not open for further replies.

bam720

Technical User
Joined
Sep 29, 2005
Messages
289
Location
US
I am trying to allow users to input data. However I stumbled upon a key error when i tried to use the '. In the past i have done a simple
Code:
$Name = str_replace("'",'`',$Name);
However, I now have abour 15 fields to check for this similar character. Is there any way to quickly and easily replace them all? I was thinking of manipulating the entire post array at once, or possibly there is a built in mysql function? Thanks.
 
Also look at the PHP function htmlentities(), as if you want the quotes displayed on output, that would be the way to go.

Also check the related functions on that page.

Good luck!

Olav Alexander Mjelde
Admin & Webmaster
 
Is there a way to run strip or addslashes to the entire post array?
 
yes

Code:
foreach ($_POST as &$val):
  $val = stripslashes($val);
endforeach;

no comment as to the advisability of this. i'd suggest assigning to a different array instead


Code:
foreach ($_POST as $key=>$val):
  $newarray[$key] = stripslashes($val);
endforeach;
 
I'd just use array_map():

$_POST = array_map ('addslashes', $_POST);

$_POST, once it is instantiated, is different from other arrays only in its variable scope. You can manipulate it any way you would a user-defined array.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top