String replace upper case to lowercase

hi

my select options are getting echo as upper case


<select>
<option><? echo strtoupper($row['category_name']); ?></option>
</select>

there are some option names that contain “&” sign. So I am replacing that sign with “&”


$row['category_name'] = str_replace("&", "&amp;", $row['category_name']);

but this outputs “&amp” as uppercase “&AMP” which gives error while validating the code


WALL &AMP; CAR CHARGER

how can i have “&amp” in lowercase and rest in uppercase

vineet


<select> 
<option><? echo str_replace('&AMP;', '&amp;', strtoupper($row['category_name'])); ?></option> 
</select>

Although it would be better to replace & with & /AFTER/ you’ve converted the text to uppercase; escaping is always the last thing you should do, for exactly the reason you’re asking this question :wink:

So, better would be:


<select> 
<option><? echo htmlentities(strtoupper($row['category_name']), ENT_COMPAT, 'UTF-8', false); ?></option> 
</select>

and then remove the part where you replace & with &

thanks scallio

this option is much better and works perfect

vineet