I want to rewrite "&" in urls as "&" I figure I need to use str_replace. I've been fiddling with it in the following code but can't get it to work so if anyone knows, perhaps you can guide me here? Thanks. $qfull = "select * from dd_banners where BannerType = '468x60' "; $rfull = mysql_query($qfull) or die(mysql_error()); if(mysql_num_rows($rfull) > '1') { while($afull = mysql_fetch_array($rfull)) { $fullBannerID[] = $afull[BannerID]; } srand ((float) microtime() * 10000000); $fullID = array_rand($fullBannerID); $FullBID = $fullBannerID[$fullID]; //get the selected banner $qfull1 = "select * from dd_banners where BannerID = '$FullBID' "; $rfull1 = mysql_query($qfull1) or die(mysql_error()); $afull1 = mysql_fetch_array($rfull1); $FullBanner = "<a href=\"$afull1[BannerURL]\"><img src=\"banners/$afull1[BannerFile]\" alt=\"$afull1[AltText]\" /></a>"; } elseif(mysql_num_rows($rfull) == '1') { $afull = mysql_fetch_array($rfull); $FullBanner = "<a href=\"$afull[BannerURL]\"><img src=\"banners/$afull[BannerFile]\" alt=\"$afull[AltText]\" /></a>"; } Code (markup):
hi 2nd hottest girl on DP after a quick look at your code, i think you should use urlencode() instead: http://php.net/urlencode
urlencode will probably change all the special characters to %. I'd do something like this, might not be as efficient but it should work. [B]$afull1[BannerURL] = str_replace('&','&',$afull1[BannerURL]);[/B] $FullBanner = "<a href=\"$afull1[BannerURL]\"><img src=\"banners/$afull1[BannerFile]\" alt=\"$afull1[AltText]\" /></a>"; Code (markup): This should change the values in your array. However, be warned, most browsers and PHP will still interpret that as a literal &. The function works, change the '&' to something like '42' and you'll see it does indeed update the array value. I'm sure you have a reason for wanting to do this but in my experience, browsers typically just switch it whenever they want so I always use the literal '&' and never had a problem. Hope this helps...
Thanks Crazy4Bass. It is so the site will validate at W3C, http://validator.w3.org/ I know the browser will parse it as regular "&", that's fine. I will try this out and let you know. I've done it in the past but don't know how to get it going with this particular script. EDIT: I guess that's not going to do it. Anyone else know? Thanks!
can you paste the source and what it gives out at this place and what you want out? Crazy4Bass' code looks fine to me.
I got it all figured out, thanks everyone! Some kind individual even rewrote the code because he said it was loops inside loops and that was bad, it's much cleaner and compact and the & is there now.