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
https://forums.phpfreaks.com/topic/61610-solved-escaping-data-in-arrays/
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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.