David Brooks
David Brooks

Reputation: 759

preg_replace Text in Email Link

I have a php string

echo $this->contact->email_to

This outputs the following HTML

<a href="mailto:[email protected]">[email protected]</a>

I want it to output the following HTML

<a href="mailto:[email protected]">&#xf0e0;</a>

I have been playing around with preg_replace but getting nowhere. I have got as far as the following code but it doesn't work at all.

echo preg_replace(array('/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i'), array('$1', '&#xf0e0;'), $this->contact->email_to);

I am no PHP expert so I understand there might be easier ways of doing this but I am having difficulty figuring it out.

Upvotes: 0

Views: 480

Answers (1)

This is probably not the best way of doing this, but using preg_replace with HTML tags, and especially emails is always a pain in the butt. Let me know if this works for you:

echo preg_replace("/\>(.*)\@(.*)\</i", ">&#xf0e0;<", $this->contact->email_to);

Upvotes: 1

Related Questions