如何保留 HTML 内容?
How to preserve HTML content?
正在尝试保留由 powerMTA 在特定位置生成的 HTML 内容。
以下是 html 内容的片段。内容-1.
<html>=0A<body>=0A<table style=3D"max-width:576px;font-family:Arial, Helvet=
ica, sans-serif;" border=3D"0" width=3D"100%" cellspacing=3D"0" cellpadding=
=3D"0" align=3D"center" >=0A<tr>=0A<td style=3D"text-align:center;">=0A<a h=
ref=3D"https://www.anshdc.com/mkt/v1/?utm_source=3Daffiliate&utm_medium=3Dc=
pv&utm_campaign=3Ddjshdjdh.com&utm_content=3Dsms&utm_term=3D1"><img src=3D"=
https://s3.sdjjfncjsj.amazonaws.com/image.ahdhdhfifkfhfi.co.in/8362/8362.jp=
g">=0A</a>=0A</td>=0A</tr>=0A</table>=0A</body>=0A</html>=0A
需要保留的内容是:Content-2.
<html>
<body>
<table style="max-width:576px;font-family:Arial, Helvetica, sans-serif;" border="0" width="100%" cellspacing="0" cellpadding="0" align="center" >
<tr>
<td style="text-align:center;">
<a href="https://www.anshdc.com/mkt/v1/?utm_source=affiliate&utm_medium=cpv&utm_campaign=villa&utm_content=sms&utm_term=1"><img src="https://s3.sdjjfncjsj.amazonaws.com/image.ahdhdhfifkfhfi.co.in/8362/8362.jpg">
</a>
</td>
</tr>
</table>
</body>
</html>
观察到Content-1中添加了=0A,每个换行符都添加了'=',文件中也添加了3D。
我们想使用 PHP 脚本解析 content-1 并将其保存为 content-2。
这是一种方法...
<?php
$sub = file_get_contents("content-1.txt"); //avoided file() cause it wont work because the last line does not end with = it did not want to take the long route of adding it first
$subb = str_replace(['=3D','=0A'],['=',''],$sub); //replace noticeable unwanted
$content = "";
$line = strtok($subb, "\r\n"); //break at end of every line even spaces are considered as chars here, !important for last line
while ($line !== false) {
$content .= substr($line,0,-1); // get content before last character on each line, where it does not exists space is considered last character
$line = strtok("\r\n");
}
file_put_contents("content-2.txt",$content);
?>
正在尝试保留由 powerMTA 在特定位置生成的 HTML 内容。
以下是 html 内容的片段。内容-1.
<html>=0A<body>=0A<table style=3D"max-width:576px;font-family:Arial, Helvet=
ica, sans-serif;" border=3D"0" width=3D"100%" cellspacing=3D"0" cellpadding=
=3D"0" align=3D"center" >=0A<tr>=0A<td style=3D"text-align:center;">=0A<a h=
ref=3D"https://www.anshdc.com/mkt/v1/?utm_source=3Daffiliate&utm_medium=3Dc=
pv&utm_campaign=3Ddjshdjdh.com&utm_content=3Dsms&utm_term=3D1"><img src=3D"=
https://s3.sdjjfncjsj.amazonaws.com/image.ahdhdhfifkfhfi.co.in/8362/8362.jp=
g">=0A</a>=0A</td>=0A</tr>=0A</table>=0A</body>=0A</html>=0A
需要保留的内容是:Content-2.
<html>
<body>
<table style="max-width:576px;font-family:Arial, Helvetica, sans-serif;" border="0" width="100%" cellspacing="0" cellpadding="0" align="center" >
<tr>
<td style="text-align:center;">
<a href="https://www.anshdc.com/mkt/v1/?utm_source=affiliate&utm_medium=cpv&utm_campaign=villa&utm_content=sms&utm_term=1"><img src="https://s3.sdjjfncjsj.amazonaws.com/image.ahdhdhfifkfhfi.co.in/8362/8362.jpg">
</a>
</td>
</tr>
</table>
</body>
</html>
观察到Content-1中添加了=0A,每个换行符都添加了'=',文件中也添加了3D。
我们想使用 PHP 脚本解析 content-1 并将其保存为 content-2。
这是一种方法...
<?php
$sub = file_get_contents("content-1.txt"); //avoided file() cause it wont work because the last line does not end with = it did not want to take the long route of adding it first
$subb = str_replace(['=3D','=0A'],['=',''],$sub); //replace noticeable unwanted
$content = "";
$line = strtok($subb, "\r\n"); //break at end of every line even spaces are considered as chars here, !important for last line
while ($line !== false) {
$content .= substr($line,0,-1); // get content before last character on each line, where it does not exists space is considered last character
$line = strtok("\r\n");
}
file_put_contents("content-2.txt",$content);
?>