removing end of file characters.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

removing end of file characters.

Post 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
clashingrocks
Forum Newbie
Posts: 1
Joined: Fri Aug 26, 2005 11:48 am

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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!
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

[SOLVED]

Post 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
Post Reply