简体   繁体   中英

Wordpress php echo inside echo?

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!

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']"); 
?>

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