需要将动态HTML内容作为字符串获取

时间:2015-11-19 11:31:01

标签: php html mysql css

我希望能够将这段代码添加到一个包围回声的#34;"

并且stil能够输出下面当前的变量。这是我的思绪严重关闭的地方。

  <td><?php echo $row_Recordset1['leaveID']; ?>&nbsp; </td>
  <td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?>&nbsp; </a></td>
  <td><?php echo $row_Recordset1['rank']; ?>&nbsp; </td>
  <td><?php echo $row_Recordset1['organisation']; ?>&nbsp; </td>
  <td><?php echo $row_Recordset1['lastName']; ?>&nbsp; </td>
  <td><?php echo $row_Recordset1['firstName']; ?>&nbsp; </td>
  <td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>

3 个答案:

答案 0 :(得分:5)

您需要使用ob_get_contents();

  

您的代码将如下所示。

<?php
ob_start();
?>

      <td><?php echo $row_Recordset1['leaveID']; ?>&nbsp; </td>
      <td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?>&nbsp; </a></td>
      <td><?php echo $row_Recordset1['rank']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['organisation']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['lastName']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['firstName']; ?>&nbsp; </td>
      <td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>

<?php
$output = ob_get_contents();
ob_end_clean();
echo $output;
?>

答案 1 :(得分:0)

cases如果您无法使用output buffering作为 @PratikSoni 建议,我建议您查找printf()sprintf()个函数以进行格式化输出

用法示例:

$output .= sprintf("<td>%s&nbsp;</td>", $row_Recordset1['leaveID']);

这样你就可以在一个变量中使用它,可以echo或者你可能需要的其他任何东西。

答案 2 :(得分:-1)

看看是否有效

<td><?php echo $row_Recordset1['leaveID']; ?>&nbsp; </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?>&nbsp; </a></td>
<td><?php echo $row_Recordset1['rank']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['organisation']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['lastName']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['firstName']; ?>&nbsp; </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>