PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] Wordpress php echo inside echo?

 January 08, 2022     php, syntax-error, wordpress     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing