简体   繁体   English

如何解码电子邮件?

[英]How to decode email?

I am scraping one page and it has e-mails like ...mailto:Stewart.Smi&#1... and similar. 我正在抓取一页,并且有类似...mailto:Stewart.Smi&#1...的电子邮件...mailto:Stewart.Smi&#1...等。 It is decoded, how could I encode it with PHP? 它已解码,如何用PHP编码? Thanks (only for education purposes). 谢谢(仅出于教育目的)。

These are just ordinary ASCII characters which for mysterious reasons have been encoded in HTMLs numeric character format. 这些只是普通的ASCII字符,出于神秘的原因,它们已经以HTML数字字符格式进行了编码。 ie the letter "a" is coded as ` 也就是说,字母“ a”的编码为` .

A list of common encodings 常用编码列表

The built in php function html-entity-decode() should convert these back to readable utf-8. 内置的php函数html-entity-decode()应将其转换回可读的utf-8。

try html_entity_decode() to get the encoded value. 尝试html_entity_decode()获取编码值。

for ex: 例如:

$str = "mailt&#111";  
$string = html_entity_decode($str);
echo $string;

Each entity is the decimal representation of a character. 每个实体都是一个字符的十进制表示形式。 This Perl code will translate simple ASCII. 该Perl代码将转换简单的ASCII。

use strict;
use warnings;

my $mail = 'mailto:Stewart.Smi&#1';

$mail =~ s/&#(\d+);/chr $1/eg;

print $mail;

OUTPUT 输出值

mailto:Stewart.Smi&#1

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

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