View Full Version : really weird problem with alternate (curved) apostrophe

03-15-2010, 08:30 AM
alright so i'm talking about the following apostrophe:

not this one:


what's weird is that when i do the following:

$var = 'What’s this';
echo str_replace('’','',$var);

i get "Whats this" (as expected)

when i do this:

$array[] = 'What’s this';
if (in_array('What’s this', $array)) {
echo 'hmm';

i get "hmm" (as expected)

and when i do this:

$array1[] = 'What’s this';
$array2 = array('What’s this', 'What is that');
$array3 = array_diff($array2, $array1);

i get "Array ( [1] => What is that )" (as expected)

but when i do this:

<form method="post"><input type="text" name="heh[]"><input type="submit" value="submit"></form>
and enter "What’s this" as the input... and do this:

$array2 = array('What’s this', 'What is that');
$array3 = array_diff($array2, $_POST);

i get:
Array ( [0] => What’s this [1] => What is that ) (not as expected)
$_POST looks just like $array1 in the previous example...

and i've tried cycling through the array's and adding all combinations of stripslashes and addslashes to do the array_diff manually but to no avail...

typing up this topic (making these examples) has actually further verified my hypothesis that the value is modified by whatever method is used to create $_POST... but i can't figure out what it's changing

03-15-2010, 08:34 AM
i just tried this:

<form method="post"><input type="text" name="heh"><input type="submit" value="submit"></form>

$array2 = array('What’s this', 'What is that');
$array3 = array_diff($array2, array($_POST['heh']));
and it worked as expected...

so the problem definitely lies with handling $_POST data that is an array (single $_POST data is fine)...
which i need to do... i'm sure i could make a workaround but it'd be a pain

03-15-2010, 08:46 AM
so the problem definitely lies with handling $_POST data that is an array (single $_POST data is fine)...Yes. When you use the name="heh[]", the POST array will contain another array named heh, where as for name="heh", the POST will be a single dimensional array, which is identical to you hard coded one.

03-16-2010, 01:38 AM
indeed... the problem however is that i HAVE to use the array format because i'm using a select menu with the "multiple" parameter enabled so that users can select multiple options.

here's a pretty similar example of what i'm trying to do:

$_SESSION['test'] = array('What’s this', 'What is that');
$_SESSION['test2'] = array('What happened', 'Who dat');
if ($_POST) {
$_SESSION['test2'] = array_merge($_SESSION['test2'], $_POST['testSelect']);
$_SESSION['test3'] = array(addslashes('What’s this'), 'What is that');
$_SESSION['test4'] = array_diff($_SESSION['test'], $_SESSION['test2']);
<form method="post">
<select name="testSelect[]" multiple="multiple" size="3">
foreach ($_SESSION['test'] as $value) {
<option value="<?php echo $value; ?>"><?php echo $value; ?>
<input type="submit" value="submit">

...just kidding... i'm unable to duplicate the problem with an example but it's still there in my actual code (which is too long to be posted/explained here), even after trying multiple layers of both stripslashes and addslashes thinking maybe they were somehow added multiple times by the $_POST handler because the select list comes from data entered into an input text field and then it can be removed by the multiple select menu (but apparently not). so i just decided to nip it in the bud and str_replace every curved apostrophe with the straight one when the user adds it to memory... oh well!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum