variables in php within html -


i working on creating admin website using adminlte free template in prosses i'm having problem getting variable within php brackets print in html page want this:

<!doctype html>   <html>     <head >  <!-- rest of page -->      <span class="info-box-text" name= "msg" >   			<!-- want print x here inside info box -->  				<script> <?php echo $x ?> </script>    	  </span>      <!-- function has output comes after called -->      <script>      <?php          somthing $x          $output_messege = "the result of something=".$x"."          ?>      </script>              </head >  </html>

the reason code doesn't work because have wrapped echo in script tag. remember php executed on server , sends out plain html. time code comes browser, echoed variable in script tag not show on page !

so can use 'echo' command print simple text or 'printf' output formatted string (useful print arrays etc)

<!doctype html> <html>     <head>     <?php           // let's 'somthing $x' later refrence has updated $x value           $output_messege = "the result of something=".$x"."           ?>   </span> </head> <body> <span class="info-box-text" name="msg">      <!-- can print output_message here simple echo. notice there no script tags ! -->     <?php echo $output_messege ?> </span> </body> </html> 

edit : elaborate, feel you've misunderstood way php , js works. php works on server. when page being rendered server 'php renderer' finds between <?php ?> markup , executes them. if put in echo there, expected, echo variable or string @ point. after plain valid html page generated no php logic or code , browser receives. js comes play. browser find under <script> </script> tag , execute it.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -