skip to Main Content

Iam not used to PHP, but after a little research i came to the following way to output a PHP Variable inside HTML (in my case its an h1 element)

if($current_month != $old_date) {
    $test = the_date( 'F' );
    echo '<h1>'.$test.'</h1>';

unfortunately, when i look in the outcoming html scource Code it looks like this :

TEST <"h1"> <"/h1"> 

so "TEST" should be inside my h1 element but its actually outside.

Anyone got an Explanation or an Idea what i do wrong?

thx in regard

3

Answers


  1. If you look at the parameters, the_date will usually echo the date immediately unless you tell it otherwise. So instead, you need to pass in all of the parameters, and pass echo as false.

     $test = the_date( 'F', '', '', false );
    
    Login or Signup to reply.
  2. hi you must at first close your if by } and then do this
    and i think maybe you

      if($current_month != $old_date) {
        $test = date( 'F' );
        echo '<h1>'.$test.'</h1>';
    }
    
    Login or Signup to reply.
  3. Try this:

    if ($current_month != $old_date) {
        $test = the_date( 'F' );
        echo "<h1>$test</h1>";
    }
    

    Or

    if($current_month != $old_date) {
        $test = the_date( 'F' ); ?>
        <h1><?php echo $test; ?></h1>
    <?php }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search