PHP: Add Div INSIDE Echo
Solution 1
Remove the semicolon after get_image function, also add the double quotes for classes name as echo is started with single quote.
<?php
echo '<div class="mydiv">' .get_image(). '</div>';
echo '<div class="mydiv">' .get_image(). '</div>';
?>
Solution 2
First thing is, you can't use semi-colon(;) in the echo method, if you are using another method inside it. For that you can use this code:
PHP
<?php
echo '<div class="your_class_name_here">' .get_image(). '</div>';
?>
xkurohatox
Self-taught in HTML/CSS/photography+photo-editing over the past year. Currently studying JS/jQuery/PHP. Although I only began posting recently, the people at Stackoverflow were my greatest teachers! TESOL/TEFL/TESL certified with a B.S. in Business + Economics (Graduated last year, but man it sure didn't teach much!). Love languages (of all kinds you could say). Wish to learn Putonghua and Russian. Art is fantastic, took a ceramics class and really enjoyed it. Formally trained in classical guitar, but bought an erhu. Just gotta motivate myself grrr. Serial entrepreneur, and boy is web development and SEO important. :) Spend most of my time these days working while playing anime or trash tv in the background. I actually like the outdoors too, although this may surprise people as my skin has changed to the color of the wallpaper; the wallpaper is gold. You'd think I'd want to stay inside, "what with all thym pawnshops and Ca$h 4 Gold places poppin' up all over this place" they argue. What they don't understand is that I actually kind of get a thrill out of going outside with my 24k skin. Don't get me wrong; it is dangerous, but at nighttime when the moon arrives, it reflects gently against me and slowly, like the feeling of falling out of love, I begin to accept -- almost without recognition -- as it receives all of my unwanted and uneasy feelings and replaces them with the sense of calm I always longed for. Maybe that is why I always return.
Updated on November 29, 2022Comments
-
xkurohatox over 1 year
I wish to add a div class INSIDE of this echo:
<?php echo get_image(); ?>
Not sure what I am doing wrong. The div class must be inside (wrapper is no good). Any suggestions?
Here are some examples of what I've tried (none work):
<?php echo '<div class=mydiv>' get_image(); ? '</div>'> <?php echo '<div class=mydiv>' .get_image();. '</div>' ?>
Thank you!
-
Domain over 8 years<?php echo '<div class=mydiv>' .get_image(). '</div>' ?> try this remove semicolon after get_image()
-
Marshall Davis over 8 yearsMake sure that
get_image()
returns a stringable result too, even though I am guessing it does in this context.
-