Checking if email content is plain text or HTML - PHP
Working with the Code Igniter framework, I receive email using the library Peeker
. Sometimes I don't get content HTML
, just plain text
emails. For simple texts, I want to replace \r\n
with <br>
, but not for HTML content. I got below function
from SO
to check if content is HTML:
function is_html($string)
{
return preg_match("/<[^<]+>/",$string,$m) != 0;
}
Below are some of the plain text texts I receive:
On 5/15/15, Mr.X wrote: > Mr. Y, > > Congratulations! Your book has been approved by our Editorial Board for > Publishing. Please send me all the fonts that you have used to type > your manuscript. Please send me the font names and the font files so that > we can proceed.......
But the function also returns TRUE
for plain text. How to differentiate?
source to share