开发者

PHP String Encoding Error

开发者 https://www.devze.com 2022-12-31 05:59 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消