PHP问题:动态加载HTML - 在PHP中设置输入值 - 存储在PHP变量中[重复]
This question already has an answer here:
[ ISSUE ]: I have created a function in php that dynamically loads html blocks of code depending on the parameters I pass, the function will be utilized to load text-boxes in one page and in another page to display the answers retrieved from the text-boxes. Example:
function chapterOne($param1, $param2) {
echo 'Welcome';
echo 'My name is '. $param1;
echo 'I am from ' . $param2;
}
# The form is going to return $name or $loc values if
# any text-box is forgotten empty when form is submitted
# ---------------------------------------------------------
$p1 = '<input type="text" placeholder="name" value="<?php echo $name; ?>" >';
$p2 = '<input type="text" placeholder="loc" value="<?php echo $loc; ?>" >';
echo chapterOne($p1,$p2);
The issue is that the value shows the php code instead of the placeholder, but only happens dynamically, when I test regular it works. Any thoughts or feedback how to overcome this issue?
Textbox example:
</div>
此问题已经存在 这里有一个答案: p>
-
PHP解析/语法错误; 以及如何解决它们?
17 answers
span>
li>
ul>
div>
[问题]: strong> 我在php中创建了一个动态加载html代码块的函数 在我传递的参数上,该函数将用于在一个页面和另一个页面中加载文本框以显示从文本框中检索的答案。 示例: p>
function chapterOne($ param1,$ param2){ echo'Welcome'; echo'我的名字是'。 $ param1; echo'我来自'。 $ param2; } #表单将返回$ name或$ loc值,如果 #在提交表单时忘记任何文本框为空 #--------- ------------------------------------------------ $ p1 ='&lt; input type =“text”placeholder =“name”value =“&lt;?php echo $ name;?&gt;” &gt;'; $ p2 ='&lt; input type =“text”placeholder =“loc”value =“&lt;?php echo $ loc;?&gt;” &gt;'; echo chapterOne($ p1,$ p2); code> pre>问题是该值显示的是php代码而不是占位符,但只会发生 动态,当我测试常规它的工作原理。 有任何想法或反馈如何克服这个问题? p>
文本框示例: p>
Use Concatenation .
$p1 = '<input type="text" placeholder="name" value="' . $name . '" >';
$p2 = '<input type="text" placeholder="loc" value="' . $loc . '" >';
echo chapterOne($p1,$p2);
You cannot start a php code block inside a php code block especially, inside quotes! If you want to use the variables for it, try this.
$p1 = <input type="text" placeholder="name" value="'.$name.'" >