Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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&maptype=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;
}
like image 941
Brian Avatar asked Jul 17 '26 09:07

Brian


1 Answers

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.'" />';
    }
}
like image 171
Gumbo Avatar answered Jul 19 '26 22:07

Gumbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!