如何在php变量中存储html? [英] how to store html in php variable?
本文介绍了如何在php变量中存储html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使一个php页面我想存储所有的html在单个php变量,然后获取使用ajax,我如何存储这个html在php变量名称#msg,这里是我的代码:
i make a php page i want to store all the html in single php variable and then get using ajax,how i store this html in php variable name #msg,here is my code:
$msg="<div id="new2" style="background:#fff; width:779px; min-height:310px;">
<table align="center" width="779px" cellpadding="0" cellspacing="0" id="tb1">
<tr style="height:28px; font-size:12px;">
<td style="width:246px">Name</td>
<td style="width:145px">CITY</td>
<td style="width:102px">ABCDEF</td>
<td style="width:71px">BUDGET</td>
<td style="width:102px">MEMBERSHIP</td>
<td style="width:84px" id="td1">UNTIL</td>
</tr>
</table>
<?php
$color='#DADDE2';
$business=getbussinesspagination(0,$start,$per_page);
if ($business){
while ($row = $business->fetch_assoc ()){
if($color=='#DADDE2')
$color='#F9F9F9';
else
$color='#DADDE2';
?>
<div id="m1" style="width:246px; height:28px; background:<?php echo $color; ?>; float:left"><p style="padding-left:45px; margin-top:8px;"><?php echo ($row['title']); ?></p></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:<?php echo $color; ?>"><p style="padding-left:30px; margin-top:8px;"><?php echo ($row['cityName']); ?></p></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:<?php echo $color; ?>"><p style="padding-left:40px; margin-top:8px;"><?php if($row['article']!=''){ echo 'A';} if($row['event']!=''){echo 'E'; } ?></p></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:<?php echo $color; ?>"><p style="padding-left:25px; margin-top:8px;"><?php echo ($row['credit']); ?></p></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:<?php echo $color; ?>"><p style="padding-left:25px; margin-top:8px;"><?php echo ($row['name']); ?></p></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:<?php echo $color; ?>"><p style="padding-left:10px; margin-top:8px;"><?php echo ($row['renewal_date']); ?></p></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:<?php echo $color; ?>"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<?php
}
}
?>
<div id="m1" style="width:246px; height:28px; background:#DADDE2; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#F9F9F9; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#DADDE2; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#F9F9F9; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#DADDE2; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#F9F9F9; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#DADDE2; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#F9F9F9; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
<div id="m1" style="width:246px; height:28px; background:#DADDE2; float:left"></div>
<div id="m2" style="width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m3" style="width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m4" style="width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m5" style="width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m6" style="width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"></div>
<div id="m7" style="width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;"><img src="messg.png" style="margin:8px 0 0 2px;"></div>
</div>
推荐答案
如果我没有错过任何内容:
If I haven't missed anything:
<?php
$msg = "<div id=\"new2\" style=\"background:#fff; width:779px; min-height:310px;\">
<table align=\"center\" width=\"779px\" cellpadding=\"0\" cellspacing=\"0\" id=\"tb1\">
<tr style=\"height:28px; font-size:12px;\">
<td style=\"width:246px\">Name</td>
<td style=\"width:145px\">CITY</td>
<td style=\"width:102px\">ABCDEF</td>
<td style=\"width:71px\">BUDGET</td>
<td style=\"width:102px\">MEMBERSHIP</td>
<td style=\"width:84px\" id=\"td1\">UNTIL</td>
</tr>
</table>";
$color='#DADDE2';
$business = getbussinesspagination(0,$start,$per_page);
if ($business)
{
while ($row = $business->fetch_assoc ())
{
if($color=='#DADDE2')
$color='#F9F9F9';
else
$color='#DADDE2';
$msg .= "<div id=\"m1\" style=\"width:246px; height:28px; background:{$color}; float:left\"><p style=\"padding-left:45px; margin-top:8px;\">{$row['title']}</p></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:{$color}\"><p style=\"padding-left:30px; margin-top:8px;\">{$row['cityName']}</p></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:{$color}\"><p style=\"padding-left:40px; margin-top:8px;\">".($row['article']!=''?'A':'').($row['event']!=''?'E':'')."</p></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:{$color}\"><p style=\"padding-left:25px; margin-top:8px;\">{$row['credit']}</p></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:{$color}\"><p style=\"padding-left:25px; margin-top:8px;\">{$row['name']}</p></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:{$color}\"><p style=\"padding-left:10px; margin-top:8px;\">{$row['renewal_date']}</p></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:{$color}\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div> ";
}
}
$msg .= "<div id=\"m1\" style=\"width:246px; height:28px; background:#DADDE2; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#F9F9F9; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#DADDE2; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#F9F9F9; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#DADDE2; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#F9F9F9; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#DADDE2; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#F9F9F9; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#F9F9F9;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
<div id=\"m1\" style=\"width:246px; height:28px; background:#DADDE2; float:left\"></div>
<div id=\"m2\" style=\"width:145px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m3\" style=\"width:101px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m4\" style=\"width:70px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m5\" style=\"width:99px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m6\" style=\"width:84px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"></div>
<div id=\"m7\" style=\"width:23px; height:28px; float:left; margin:0 0 0 1px;background:#DADDE2;\"><img src=\"messg.png\" style=\"margin:8px 0 0 2px;\"></div>
</div>";
echo $msg;
?>
这篇关于如何在php变量中存储html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文