starmonkey
starmonkey

Reputation: 3157

Filter/parse/modify emails and hrefs from html content in PHP4

I'm not validating emails. What I want to do is find (and then change) 3 separate types of "email" content in a (html) string:

  1. a plain email: eg [email protected]
  2. a mailto href: eg <a href="mailto:[email protected]">[email protected]</a>
  3. an aliased href: eg <a href="mailto:[email protected]">user's email</a>

I'm then going to transform each example into a custom html string that will then be modified by JS (anti-spam harvesting via Spamspan):

<span class="spamspan">
<span class="u">user</span>
@
<span class="d">example.com</span>
(<span class="t">Spam Hater</span>)
</span>

So you can see I also have to find these types of input, parse the email into user, domain and (optionally) a display value. I'm struggling at the moment with regexes to find these emails... parsing them should be straightfoward in PHP.

Edit: At the moment, I'm locked into PHP4. Will take a look at http://php-html.sourceforge.net/ for parsing HTML.

Upvotes: 0

Views: 274

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799062

You need a HTML parser and an email regex.

Upvotes: 1

Related Questions