鍍金池/ 問答/PHP  HTML/ 下面這個(gè)html字符串,如何用php的 echo或print來輸出?

下面這個(gè)html字符串,如何用php的 echo或print來輸出?

下面這個(gè)html字符串,如何用php的echoprint來輸出?

<td width=275><input type="text" name="title" value="<?php echo $row['title']; ?>"></td>  
echo "<td width=275><input type="text" name="title" value="<?php echo $row['title']; ?>"></td>"

不可以

echo '<td width=275><input type="text" name="title" value="<?php echo $row['title']; ?>"></td>'

也不可以

print <<<EOT
<td width=275><input type="text" name="title" value="<?php echo $row['title']; ?>"></td>
EOT;

也不可以,應(yīng)為,這段html還包含php語句。

我的真實(shí)需求是

<?php
if(isset($_POST['flag'])
{ 
print <<<EOT
<td width=275><input type="text" name="title" value="<?php echo $row['title']; ?>"></td>
EOT;
else 
{

} 
?>
回答
編輯回答
汐顏

2種實(shí)現(xiàn)方式

1.把html代碼直接寫在頁面,與php標(biāo)簽分開

<?php
//你的其他php代碼
$row = ['title' => '123'];
?>
<td width=275><input type="text" name="title" value="<?= $row['title']; ?>"></td>
<?php
//你的其他php代碼
?>

2.html采用PHP的字符串內(nèi)賦值

echo "<td width=275><input type=\"text\" name=\"title\" value=\"{$row['title']}\"></td>"

<?php
$_POST['flag'] = true;
$row = ['title' => '111', 'ugly' => '222'];
?>

<?php if (isset($_POST['flag'])): ?>
  <td width=275>
    <input type="text" name="title" value="<?= $row['title']; ?>">
  </td>
<?php else: ?>
  <td width=275>
    <input type="text" name="title" value="<?= $row['ugly']; ?>">
  </td>
<?php endif; ?>

1并不是不能滿足你需求

2018年9月9日 08:34
編輯回答
哚蕾咪

你需要的是eval函數(shù)。
看官方手冊: http://php.net/manual/zh/func...

2018年5月14日 05:45
編輯回答
硬扛
//方法1
echo '<td width=275><input type="text" name="title" value="'.$row['title'].'"></td>';

//方法1變形體
$a = '<td width=275><input type="text" name="title" value="';
$a .= $row['title'];
$a .= '"></td>';
echo $a;

//方法2
echo
<<<EOT
<td width=275><input type="text" name="title" value="{$row['title']}"></td>
EOT;
2018年8月18日 06:20