Home > OS >  How to sub a html and php code with php open and close tag into a php echo function
How to sub a html and php code with php open and close tag into a php echo function

Time:11-20

I want to echo out this code but there's already open and close php tag , so how do I sub the html and php in the echo and make the php function works.

This is the code that I want to echo it out.

<div class="tutor-zoom-join-button-wrap">
     <a href="<?php echo $browser_url; ?>" target="_blank" class="tutor-btn tutor-button-block"><?php echo $browser_text; ?></a>
     <a href="<?php echo $meeting_data['join_url']; ?>" target="_blank" class="tutor-btn bordered-btn tutor-button-block"><?php _e('Join in Zoom App', 'tutor-pro'); ?></a>
</div>

This is the function that I made(replace with code above with 123)

    <?php
                    $var1 = 1;

                    if ($var1 = 1) {

                        echo "123 ";

                        } else {
                        echo "The course ID, password and join button will only be shown before 30min of course start";
                        };
                
?>

This is what I try but not working

<?php
                    $var1 = 1;

                    if ($var1 = 1) {

                        echo 

                        "<div hljs-string">">"
                            "<a href="," .$browser_url. " ," target="_blank" hljs-string">">",.$browser_text."</a>",
                            "<a href=",".$meeting_data['join_url']." ,"target="_blank" hljs-string">">"._e('Join in Zoom App', 'tutor-pro')."</a>",
                        "</div>",
                    "</div>" ;

                        } else {
                        echo "The course ID, password and join button will only be shown before 30min of course start";
                        };


                    
?>

CodePudding user response:

I have modified your code. Please check and you also refer to some PHP tutorials to learn php.

<?php
$var1 = 1;

if ($var1 == 1) {

    echo 

    "<div class='tutor-zoom-join-button-wrap'>
        <a href=" .$browser_url. " target='_blank' class='tutor-btn tutor-button-block'>".$browser_text."</a>,
        <a href=".$meeting_data['join_url']."target='_blank' class='tutor-btn bordered-btn tutor-button-block'>"._e('Join in Zoom App', 'tutor-pro')."</a>",
    "</div>",
"</div>" ;

    } 
else {
        echo "The course ID, password and join button will only be shown before 30min of course start";
    }

              
?>

CodePudding user response:

The problem is in the long string you want to echo. The double quote " starts and ends the string. You have started and ended the string several times when what you want is one long string. If you want to use a double quotes inside the string you have to precede it with a slash \". To concatenate strings you need to use a dot .. Double quotes also allow you to place variables inside the string that will be replaced. So your echo statement could be done like this:

echo
    "<div class=\"tutor-zoom-join-button-wrap\">" .
        "<a href=\"$browser_url\" target=\"_blank\" class=\"tutor-btn tutor-button-block\">$browser_text</a>" .
        "<a href=\"$meeting_data['join_url']\" target=\"_blank\" class=\"tutor-btn bordered-btn tutor-button-block\">" . _e('Join in Zoom App', 'tutor-pro') . "</a>" .
     "</div>" .
  "</div>" ;  // Note that this tag does not appear to be necessary based on the code you have shown

CodePudding user response:

You can write it like this:

<?php
$var1 = 1;
if ($var1 = 1) {
    echo `<div class="tutor-zoom-join-button-wrap">
            <a href="`.$browser_url.`" target="_blank" class="tutor-btn tutor-button-block">`.$browser_text.`</a>
            <a href="`.$meeting_data['join_url'].`" target="_blank" class="tutor-btn bordered-btn tutor-button-block">`._e('Join in Zoom App', 'tutor-pro').`</a>
        </div>
    </div>` ;
} else {
   echo "The course ID, password and join button will only be shown before 30min of course start";
};

?>

Hope It will work for you!

  •  Tags:  
  • php
  • Related