Skip to content
Advertisement

Remove char from imap mail extract

I am trying to fetch a mail in imap from Google, I’m using the imap() function from PHP IMAP library and I want to use a preg_match() call on my mail content but I have a strange issue, I have curious break lines altering the normal preg_match().

More details: I have in my markup something like that:

JavaScript

I am running this code to extract the body for example:

JavaScript

The output of this code is:

JavaScript

And the extracted value is an empty array… After further investigation i discovered through a var_dump() of my source string that there is a at the end of each line.
I have no clue of what this html char code is and how to remove it.

Advertisement

Answer

Well the first thing is I’m assuming that you have run imap_mime_header_decode already and you have the result.

Assuming you’re working in the UTF8 charset and not ISO-8859-1 or ISO-8859-15 charsets you can try

JavaScript

EDIT Whoops… to remove or replace the char you can use

JavaScript

Just place your alternative character in where is. You can replace it with nothing by doing

JavaScript

You can also run an array through preg_replace like

JavaScript

This may also be relevant to you.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement