Issue
Wordpress, echo inside echo
Error: syntax error, unexpected string content "", expecting "-" or identifier or variable or number
<?php
echo do_shortcode("[simple-weather location='$_SERVER['IP2LOCATION_CITY'], $_SERVER['IP2LOCATION_COUNTRY_SHORT']' days='6' night='no' units='metric' text_align='center' display='block' style='large-icons' api='1f2420650944ec72e4acd03a7ed18514']");
?>
I would be grateful for your help in debugging the code!
Solution
Just enclose the PHP variables in curly brackets. As currently written, PHP thinks that the variable is only $_SERVER and not the $_SERVER['IP2LOCATION_CITY']. When complex variables like array items or object properties are used in quotation marks, always add curly brackets around them to help PHP distinguish what is a variable and what is plain text.
Here is a working code:
<?PHP
echo do_shortcode("[simple-weather location='{$_SERVER['IP2LOCATION_CITY']}, {$_SERVER['IP2LOCATION_COUNTRY_SHORT']}' days='6' night='no' units='metric' text_align='center' display='block' style='large-icons' api='1f2420650944ec72e4acd03a7ed18514']");
?>
Answered By - Ivica Pesovski
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.