Jump to content

[SOLVED] Escaping data in arrays


graham23s

Recommended Posts

Hi Guys,

 

i have an array with users heights like this:

 

     $height_array =array("5'0" (152 cm)",
                          "5'1" (155 cm)",
                          "5'2" (157 cm)");

 

because of the ' and " its not working properly

 

i have escaped them:

 

     $height_array =array("5\'0\" (152 cm)",
                          "5\'1\" (155 cm)",
                          "5\'2\" (157 cm)");

 

is this valid to do that or is there another wya i can do it?

 

thanks guys

 

Graham

Link to comment
Share on other sites

Thats probably the way you're going to have to do it, or, if this is just for output, you could use the HTML entity:

"

for the double quotes and:

'

for the singles. Although you dont need to escape the single quotes if you are surrounding your string in doubles.

Link to comment
Share on other sites

Hi GR,

 

it's basically an array so i can foreach it to display back to the user what he/she has selected:

 

<?php 
                #########################################################################
                foreach ($height_array as $value) {
                echo "<option Value=\"{$value}\"";
                if ($value == $hair) { echo 'SELECTED'; }
                echo ">{$value}</option>";
                }
                #########################################################################  
?>

 

kinda thing

 

thnaks for the input mate

 

Graham

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.