PHP: Add Div INSIDE Echo

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?

Read More

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!

Related posts

3 comments

  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>'; 
    ?>
    
  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>';
    ?>
    
  3. If it gets more easy, you also can also do:

    <?php 
    echo "<DIV CLASS='yourclass'>"; get_image();
    echo "</div>";    
    ?>
    

Comments are closed.