如何在PHP内部的PHP中编写php? [英] How to write php within html within php?
问题描述
所以我会喜欢一个简单的显示和告诉如何使以下代码解析,谢谢:
<?php
if (!isset($ _ POST ['myform'])){
echo
< form method =POSTaction =<?php if(isset($ myform_worked)) {echo'somepath';}?>接收字符集= UTF-8 >
这是我试过的,但上面的一行并不解析:
<?php
if(!isset($ _ POST ['myform'])){
echo
'< form method =POSTaction ='<?php if(isset($ myform_worked)){echo'somepath';}?>'accept-charset =UTF- 8&$'
我也尝试过(在PHP里面使用双引号:
<?php if(isset($ myform_worked)){echo'somepath';}?>
请显示这个nub如何做到这一点,谢谢,我不在乎上面的代码是否是BAD ...我只是需要学习如何逃避/解析php里面的html里面php,谢谢。
你没有关闭打开的php块工作语法将如下所示:
<?php
// php code
?>
<! - HTML代码 - >
<?php
?>
或根据您的问题:
<?php
if(!isset($ _ POST ['myform'])){
?>
< form method =POSTaction =<?php if(isset($ myform_worked)){echo'somepath';}?&接收字符集= UTF-8 >
<?php} // if-closing bracket?>
I have recently asked this question, but rather than getting a direct answer, I was shown how to use the ternary operator to simplify my code by substituting if statements inside my html with variables, which I appreciated and put to use - however that also caused other code to be harder to read and ultimately did not teach me to properly escape/parse php in code similar to that below.
So I would love a simple 'show and tell' of how to make the following code parse, thank you:
<?php
if (!isset($_POST['myform'])) {
echo
<form method="POST" action="<?php if (isset($myform_worked)) { echo 'somepath'; } ?>" accept-charset="UTF-8">
This is what I've tried, but the line above doesn't parse:
<?php
if (!isset($_POST['myform'])) {
echo
'<form method="POST" action="'<?php if (isset($myform_worked)) { echo 'somepath'; } ?>'" accept-charset="UTF-8">'
I have also tried (using double quotes around the php inside :
"<?php if (isset($myform_worked)) { echo 'somepath'; } ?>"
Please show this nub how to do this, thanks. I do not care if the above code is BAD... I just need to learn how to escape/parse php inside html inside php, thanks.
You did not close the open php-block beforehand. The working Syntax would be like this:
<?php
//php code
?>
<!--HTML-Code-->
<?php
?>
Or according to your problem:
<?php
if (!isset($_POST['myform'])) {
?>
<form method="POST" action="<?php if (isset($myform_worked)) { echo 'somepath'; } ?>" accept-charset="UTF-8">
<?php } //if-closing bracket ?>
这篇关于如何在PHP内部的PHP中编写php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!