简体   繁体   中英

PHP breaking URL by encoding ampersand

I'm debugging a site where this code is intended to display in image:

<a href="<?=$auction_link;?>"><img src="<? echo ((!empty($main_image)) ? 'thumbnail.php?pic=' . $main_image . '&w=' . $layout['hpfeat_width'] . '&sq=Y' : 'themes/' . $setts['default_theme'] . '/img/system/noimg.gif');?>" border="0" alt="<?=$item_details[$counter]['name'];?>"></a>

No image is displayed, evidently because the href value is being converted to:

thumbnail.php?pic=uplimg/img_A_100430_b93204949c62ffba35eb62f1b94b93c4.jpg&amp;w=0&amp;sq=Y"

When it should be:

thumbnail.php?pic=uplimg/img_A_100430_b93204949c62ffba35eb62f1b94b93c4.jpg&w=250&sq=Y

Note the &amp; where the & should be in two places. Is there anyway to stop the encoding?

Thanks - Joe

Try using &amp; in your PHP source. PHP does not encode the ampersand by the way.

/*...*/ $main_image . '&amp;w=' . $layout['hpfeat_width'] . '&amp;sq=Y' /*...*/

You are encoding for HTML instead of for URLS.

If you want the ampersand to be data rather than control - that is, if you want the ampersand passed to the server as part of a parameter name or value rather than as a separator betweek key-value pairs, you want to use %xx encoding, where xx is the hexadecimal value of the character you want to encode.

If you don't want it encoded at all, you need to find the code that's doing the encoding snd remove it (nothing happens by magic).

Okay, it looks like there is a different problem. The variable $layout['hpfeat_width'] doesn't seem to be converting correctly. When I replace it with a hard value, it works. Thanks everyone for taking a moment to look at this!

Best - Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM