Page 1 of 1

removing end of file characters.

Posted: Fri Aug 26, 2005 10:16 am
by EricS
I'm writing an app that reads a couple of files (a text file and an html file) in off the server and builds a multipart email out of the two files. The text is used as the plain text alternative and the html is used as the html part for those email clients that support it.

I'm using file_get_contents() to read the contents of the two files into strings. The problem I'm having is that the resulting strings are containing the end of file characters (at least I think they are) and I need to strip those out. If I send the email with those end of file characters still in the strings, nothing in the email past the first end of file is sent.

So how do I strip those out so I can get the entire email to send?

Thanks,
Eric Stewart

Posted: Fri Aug 26, 2005 11:52 am
by clashingrocks
You can use PHP's rtrim to remove characters from the end of the string. Here's a link for more information on the rtrim function:

http://us3.php.net/rtrim

Posted: Fri Aug 26, 2005 12:00 pm
by jayshields
i dont think get_file_contents() would read a .html (f.e.) and put .html on the end of the string, atleast it doesnt for me.

but if you knew the extension you want to strip just use substr($string, 0, -5), that would work for extensions such as .html.

i might be way off what you want here, if so, explain more :)

ps. i left this window open for about an hour sorry if about 50 other people have said same thing!

Posted: Fri Aug 26, 2005 12:07 pm
by nielsene
I'm not sure if the NUL byte is the problem here. Are you setting up all the normal MIME headers properly? If you want to send both the raw text and HTML versions, that will require setting up a multi-part email using MIME.

If the NUL byte really is the problem you could try just doing something like

Code: Select all

$str=substr($str,0,-1);
to remove the final character.

[SOLVED]

Posted: Fri Aug 26, 2005 12:22 pm
by EricS
The rtrim() on the file extracted string solved the problem. The emails are now sent out with both the html and plain text version and work perfectly.

Thank you clashingrocks, jayshields, and nielsene for all your help.

Eric Stewart