你能在html中嵌入一条嵌入php的php指令吗?
我试过这样的方法:你能在html中嵌入一条嵌入php的php指令吗?,php,html,Php,Html,我试过这样的方法: // $count is an incrementing number echo '<td><input type = "radio" name = "selected" value = "<?php echo htmlspecialchars($count); ?>"></td>'; /$count是一个递增的数字 回声''">'; } else如果(strcmp($key,“body”)==0{/*不为bod
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value = "<?php echo htmlspecialchars($count); ?>"></td>';
/$count是一个递增的数字
回声''">';
}
else如果(strcmp($key,“body”)==0{/*不为body创建单元格*/}
else{echo“$value”;}
}
}
为什么不将字符串和嵌入的“>”连接起来呢;
注意:我还认为您对PHP和HTML的解释有一个基本的误解:
它不能工作,因为您不能像它抛出php解析错误那样连接字符串。我没有足够的声誉来评论,所以我添加了我自己的答案:
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value ="' . htmlspecialchars($count) . '"></td>';
/$count是一个递增的数字
回声';
不能在另一个php打开/关闭标记中添加新的php打开/关闭标记
更新:
实际上,输出脚本生成的整数变量不需要htmlspecialchars()函数,所以也可以跳过它。他可能只是希望有一个简单的方法;)@jsve不幸的是,这不起作用。@flyinheagle413我不知道你说的简单的解决办法是什么意思?@Devin_Kinh,如果这不起作用,你能为你的问题添加一些上下文吗?周围的代码是什么样子的?@jsve我添加了我在其中使用的函数。谢谢,我没有意识到我不需要脚本标签!
function makeRow($row_name,$row_ticket) {
//create html table row from mysql table row passed as ticket object param
$count = 0;
foreach ($row_array as $key => $value) {
# code...
$count++;
if(strcmp($key, "select")==0){
echo '<td><input type = "radio" name = "selected"
value ="' . <?php echo htmlspecialchars($count); ?> . '"></td>';
}
else if(strcmp($key, "body")==0){/*do not make cell for body*/}
else { echo "<td>$value</td>";}
}
}
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value ="' . <?php echo htmlspecialchars($count); ?> . '"></td>';
<td>
<input type="radio" name="selected" value="<?php echo "$count"; ?>">
</td>
// $count is an incrementing number
echo '<td><input type = "radio" name = "selected"
value ="' . htmlspecialchars($count) . '"></td>';