View Full Version : str_replace lowercase problem

05-20-2011, 03:24 PM
I have a problem with str_replace function. I am replacing some chars and spaces so that I can use them i.e. as id of div.

For some reason one time it outputs like " alfaromeo" and the other time like it should be "AlfaRomeo" - any ideas ?

$marki = array ("Alfa Romeo", "Audi");
$replacestr = array(' ', '(', ')', '/', '-');

<? foreach ($marki as $marka) {
echo '<a href="javascript:toggle("' . str_replace($replacestr, '', $marka) . '");">' . $marka . '</a>
<div id="' . str_replace($replacestr, '', $marka) . '" style="display: none" class="textli">';


<a href="javascript:toggle(" alfaromeo");">Alfa Romeo</a>
<div id="AlfaRomeo" style="display: none" class="textli">

05-20-2011, 03:33 PM
Not with what you have posted here it doesn't. The code you have has an additional space preceding the string which doesn't exist, and str_replace will not cause a replacement of case. Combined with the additional set of <? and ?> tags (you should avoid using short_tags btw), tells me there is code between the first two variables you've declared and the foreach which is affecting the $marki result.
I'm betting that JS code won't work properly either. The use of the double quotes within the double quotes indicates to HTML that you have completed an attribute, so those should be changed to escaped single quotes.