Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts

    really weird problem with alternate (curved) apostrophe

    alright so i'm talking about the following apostrophe:
    Code:
    not this one:
    Code:
    '
    what's weird is that when i do the following:
    Code:
    $var = 'What’s this';
    echo str_replace('’','',$var);
    i get "Whats this" (as expected)

    when i do this:
    Code:
    $array[] = 'What’s this';
    if (in_array('What’s this', $array)) {
        echo 'hmm';
    }
    i get "hmm" (as expected)

    and when i do this:
    Code:
    	$array1[] = 'What’s this';
    	$array2 = array('What’s this', 'What is that');
    	$array3 = array_diff($array2, $array1);
    	print_r($array3);
    i get "Array ( [1] => What is that )" (as expected)

    but when i do this:
    Code:
    <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:
    Code:
    	$array2 = array('What’s this', 'What is that');
    	$array3 = array_diff($array2, $_POST);
    	print_r($array3);
    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

  • #2
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    i just tried this:
    Code:
    <form method="post"><input type="text" name="heh"><input type="submit" value="submit"></form>
    Code:
    $array2 = array('What’s this', 'What is that');
    	$array3 = array_diff($array2, array($_POST['heh']));
    	print_r($array3);
    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

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts

    Cool

    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:

    Code:
    	$_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">
    <?php
    	foreach ($_SESSION['test'] as $value) {
    ?>
    			<option value="<?php echo $value; ?>"><?php echo $value; ?>
    <?php
    	}
    ?>
    		</select>
    		<input type="submit" value="submit">
    	</form>
    ...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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •