I am a complete newbie to PHP, but found it can be very useful. How to write the following statement in PHP:
If the identifier is body = "home", then insert some html, for example.
<h1>I am home!</h1>
Otherwise, paste this html:
<p>I'm not home.</p>
Thank!
Doing this with the built-in PHP template:
<?php if ($bodyID==='home') { ?> <h1>I am home!</h1> <?php } else { ?> <p>I'm not home!</p> <?php } ?>
You can try:
$html = ''; if ( $body_id === 'home' ) { $html .= '<h1>I am home!</h1>'; } else { $html .= '<p>I\'m not home.</p>'; } echo $html;
This will reflect the html code depending on the $ body_id variable and what it contains.
:
switch($body) { case 'home': //$body == 'home' ? echo '<h1>I am home!</h1>'; break; case 'not_home': default: echo '<p>I'm not home.</p>'; break; }
default , $body case, , default .
default
$body
case
, , if/else, / :
if
else
<?php if ($body == 'home'):?> <h1>I am home!</h1> <?php else:?> <p>I'm not home!</p> <?php endif; ?>
, $bodyID :
<?php if ($bodyID==='home') { echo "<h1>I am home!</h1>";} else { echo "<p>I'm not home!</p>";} ?>
, (, $body - ) - javascript, "" JS PHP .
<script language="javascript"> <!-- if( document.body.id === "home" ){ window.document.write("<h1>I am home!</h1>") ; } else{ window.document.write("<p>I'm not home!</p>") ; } --> </script>
, body.id $_GET... , , body.id.
, .
Source: https://habr.com/ru/post/1773211/More articles:Web application: code from scratch or using a third-party structure? - phpGroovy performance - performanceGroovy: Poor multithreading performance and slow computing compared to Java? - javadjango-paypal changes currency to euro - djangoBest practice to solve application cold start problem - pythonC # Return private objects - c #Telerik management and user interface automation? - integration-testingHow to change input language in C # code? - c #How to use CONCAT in JOIN - sqlRemove duplicate entries from nested dictionary if two values ββmatch, in Python - pythonAll Articles