PHP HTML Decode

杀马特。学长 韩版系。学妹 提交于 2020-01-30 06:42:50

问题


I'm forced to work with HTML that looks like this:

<font color=3D=22=236EAED2=22 style=3D=22font-siz=
e:13px;font-family:arial;=22><B>Some Info Here</B></font></=
A></td></tr><tr><td><font color=3D=22=23FFFFFF=22 style=3D=22font-size:11=
px;font-family:arial;=22>192 Wellington Parade =7C Melbourne =7C  VIC =7C=
Australia 3002</font></td></tr><tr><td><font color=3D=22=23FFFFFF=22 st=
yle=3D=22font-size:11px;font-family:arial;=22>T: 61-<a href=3D=22=23=22 s=
tyle=3D=22color:=23FFFFFF; text-decoration:none=22>

It looks like " gets converted to =22 and so on. There is also other "codes" like =7C =3D, = before every new line and so on.

&nbsp; is =26nbsp;

Is there any function or technique for restoring to proper HTML?

Thank you.


回答1:


use quoted_printable_decode("YOUR String to decode"); OR imap_qprint("Your String to decode")

Check FIDDLE

Description : quoted_printable_decode — Convert a quoted-printable string to an 8 bit string

his function returns an 8-bit binary string corresponding to the decoded quoted printable string (according to » RFC2045, section 6.7, not » RFC2821, section 4.5.2, so additional periods are not stripped from the beginning of line).

More Info and here too




回答2:


That’s the quoted-printable encoding, which can be decoded with quoted_printable_decode.

Like so:

$input= "the string that you need to be decoded";
$output = quoted_printable_decode($input);
echo $output;



回答3:


It looks like they're simply replacing '%' with =. You say that =22 gets translated into '"', and %22 is the url encoding character for ".

Look here for a chart, and you can probably figure out a way to replace the characters with PHP.

Also, quotedprintable and htmlspecialchars could be of some use



来源:https://stackoverflow.com/questions/26804118/php-html-decode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!