Solved

PHP echo single quote breaking echo

Posted on 2011-09-30
5
378 Views
Last Modified: 2012-05-12
I am trying to use a dynamic variable in a Wordpress shortcode in a theme using do_shortcode like this:

<?php echo do_shortcode('[map id="map1" address="<?php echo($row['fulladdress']); ?> <?php echo($row['city']); ?>, <?php echo($row['zip']); ?> " z="15"]'); ?>

Open in new window


That does not work...this does though so I know its my echo statements breaking it because this does work:

<?php echo do_shortcode('[map id="map1" address="Austin, TX " z="15"]'); ?>

Can someone help me figure out how to format this?
0
Comment
Question by:pda4me
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Chris Harte
Comment Utility
I don't know anything about wordpress or do_shortcode, but I can tell you have a lot of mismatched braces and brackets in there. Do not echo variables or use  php tags inside php tags. That z=15 is just hanging loose on the end of that line. I can not tell what you are trying to do with it. But try this.


$content = '[map id="map1" address="'.$row['fulladdress'].'"';

echo do_shortcode ($content);


echo($row['city']);
echo($row['zip']);
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
Using echo inside echo seems out of place to me.  And echo is not a function so you can remove the parentheses.

I think you might be looking for something like this, but it is hard to guess:

$str = '[map id="map" address="';
$str .= $row['fulladdress'];
$str .= '"';
$str .= ' ' . $row['city'];
$str .= ' ' . $row['zip'];
$str .= '"'
$str .= '  z="15"]';

echo do_shortCode($str);

It is much easier to get the code right if you do not use compound statements.
0
 

Author Comment

by:pda4me
Comment Utility
i need the city and zip and the closing bracket ] to finish the short code?  How do I include those?  Nothing I try worked?
0
 

Author Closing Comment

by:pda4me
Comment Utility
Bingo, thanks Ray!!!
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks for the points!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress syntax error 1 27
how to resize preview image 4 28
session dropped in IE 10 18
php connect() failed error 25 6
In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now