good_evening
good_evening

Reputation: 21749

How to decode email?

I am scraping one page and it has e-mails like ...mailto:Stewart.Smi&#1... and similar. It is decoded, how could I encode it with PHP? Thanks (only for education purposes).

Upvotes: 0

Views: 3226

Answers (3)

Punit
Punit

Reputation: 1120

try html_entity_decode() to get the encoded value.

for ex:

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

Upvotes: 1

James Anderson
James Anderson

Reputation: 27478

These are just ordinary ASCII characters which for mysterious reasons have been encoded in HTMLs numeric character format. i.e. the letter "a" is coded as `.

A list of common encodings

The built in php function html-entity-decode() should convert these back to readable utf-8.

Upvotes: 2

Borodin
Borodin

Reputation: 126722

Each entity is the decimal representation of a character. This Perl code will translate simple ASCII.

use strict;
use warnings;

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

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

print $mail;

OUTPUT

mailto:Stewart.Smi&#1

Upvotes: 0

Related Questions