简体   繁体   English

PHP使用备用引号回显HTML表

[英]PHP echo an HTML table with alternate quote marks

I'm trying to use PHP echo to call a big styled HTML table that someone has provided for me. 我正在尝试使用PHP echo来调用某人为我提供的大样式HTML表。 The problem that I'm encountering is the HTML tables was coded with both double quotes ("") and single quotes ('') when defining classes and arguments/parameters. 我遇到的问题是HTML表在定义类和参数/参数时用双引号(“”)和单引号('')编码。 I'm able to get the table to display properly if I take a long time to change everything to single or double quotes, but is there an easier way to display the table without doing this? 如果我花了很长时间将所有内容更改为单引号或双引号,我能够正确显示表格,但有没有更简单的方法来显示表格而不这样做?

Here is an example of a smaller table that has been provided for me: Please note the alternate ' and " 这是一个为我提供的小表的示例: 请注意备用'和'

<div class='ws-schedule' id='ws-schedule1'>
<table>
<tr class='topheader'><th class='rowheader'></th><th>11am</th><th>12pm</th><th>1pm</th><th>2pm</th><th>3pm</th><th>4pm</th><th>5pm</th><th>6pm</th><th>7pm</th><th>8pm</th></tr>
<tr class='row1'>
<th rowspan='1' class='rowheader'>Sun</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='Work' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">Work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='Gym' id='continueright' colspan='2' class='cat1'><div class="ws-item-title ws-item-title-1">Gym</div></td></tr><tr class='row1'>
<th rowspan='1' class='rowheader'>Mon</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='Work' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">Work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='Gym' colspan='1' class='cat1'><div class="ws-item-title ws-item-title-1">gym</div></td></tr><tr class='row1'>
<th rowspan='1' class='rowheader'>Tue</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='work' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='gym' colspan='1' class='cat1'><div class="ws-item-title ws-item-title-1">gym</div></td></tr><tr class='row1'>
<th rowspan='1' class='rowheader'>Wed</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='work' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='gym' colspan='1' class='cat1'><div class="ws-item-title ws-item-title-1">gym</div></td></tr><tr class='row1'>
<th rowspan='1' class='rowheader'>Thu</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='Possible work day//' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">Possible Work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='gym' colspan='1' class='cat1'><div class="ws-item-title ws-item-title-1">gym</div></td></tr><tr class='row1'>
<th rowspan='1' class='rowheader'>Fri</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='work' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='gym' colspan='1' class='cat1'><div class="ws-item-title ws-item-title-1">gym</div></td></tr><tr class='row1'>
<th rowspan='1' class='rowheader'>Sat</th>
<td class="ws-item-1" style= "background-color:#FFA100;"tooltip='work' colspan='4' class='cat1'><div class="ws-item-title ws-item-title-1">work</div></td><td></td>
<td></td>
<td></td>
<td></td>
<td class="ws-item-1" style= "background-color:#0074A2;"tooltip='gym' colspan='1' class='cat1'><div class="ws-item-title ws-item-title-1">gym</div></td><td></td></tr></table></div>

Use your IDE to add slash before the qoute by using find And replace 使用IDE在qoute之前添加斜杠,使用find and replace

For example if you want to use double qoute echo "text 'text' \\"test\\" text"; 例如,如果你想使用double qoute echo“text”text'\\“test \\”text“;

Hope this helps 希望这可以帮助

You could use a HEREDOC as @Dagon suggests: 您可以使用HEREDOC因为@Dagon建议:

$tableHTML = <<<TABLE_HTML
<div class='ws-schedule' id='ws-schedule1'>
<table>
...
</table>
</div>
TABLE_HTML;

However, I'm not sure you should do this in this instance. 但是,在这种情况下,我不确定你应该这样做。 This is provided to you statically. 这是静态提供给您的。 Presumably youre not add any PHP output to the table (otherwise why not just fix it while youre in there?) so I would just pull the content from the file similar to if you use file_get_contents() : 大概是你没有在表中添加任何PHP输出(否则为什么不在你那里时修复它?)所以我只是从文件中提取内容类似于你使用file_get_contents()

function file_get_contents_php($file, array $vars = null) {

   if (null !== $vars) {
      extract($vars);
   }

   ob_start();
   include($file);
   $html = ob_get_clean();
   return $html;
}

Usage would look like: 用法如下:

$tableHTML = file_get_contents_php('path/to/table.html');

This gets you the markup as a single string, and it keeps this table isolated so its not the random big string in your block of code which will make it much easier to update. 这可以让你的标记为一个字符串,它会持续此表在你的代码,这将使它容易更新块孤立所以它不是随机大串。

I'd do it this way instead of using file_get_contents() because this way if you ever need to add a bit of php to it you can: 我这样做而不是使用file_get_contents()因为这种方式,如果你需要添加一些PHP,你可以:

$tableHTML = file_get_contents_php('path/to/table.html', array(
    'title' => 'A variable to be referenced by $title in table.html'
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM