PHP String Encoding Error
I'm trying to get the following code to output an IMG tag with the URL for Google Static Maps API http://code.google.com/apis/maps/documentation/staticmaps/#Imagesizes embedded in there... the result is that everything except the $address is being output successfully... what am I doing wrong?
function event_map_img($echo = true){
global $post;
$address = get_post_meta($post->ID, 'date_address', true);
if($echo): echo '<img src="'.'http://maps.google.com/maps/api/staticmap?center='.$address.'&zoom=14&size=700x512&m开发者_开发问答aptype=roadmap&markers=color:blue|label:X|'.$address.'&sensor=false" />';
else:
return '<img src="'.'http://maps.google.com/maps/api/staticmap?center='.$address.'&zoom=14&size=700x512&maptype=roadmap&markers=color:blue|label:X|'.$address.'&sensor=false" />';
endif;
}
Try this:
function event_map_img($echo = true) {
global $post;
$address = urlencode(get_post_meta($post->ID, 'date_address', true));
$src = htmlspecialchars('http://maps.google.com/maps/api/staticmap?center='.$address.'&zoom=14&size=700x512&maptype=roadmap&markers=color:blue|label:X|'.$address.'&sensor=false');
if ($echo) {
echo '<img src="'.$src.'" />';
} else {
return '<img src="'.$src.'" />';
}
}
I think you are missing the &
separator for $address
after blue|label:X|
, it should be like:
'&address=' . $address
精彩评论