Re: spaces - not sure if this is a preg_match issue or a regexp issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



DeadTOm wrote:
I'm working on a script to look for a UUEncoded attachment in an NNTP
message. I'm running into problems with spaces in the filename of the
attachment.
UUEncoded files in the body of a message will start with the word "begin",
then the size of the file, then the name of the file. Then the encoded
file, finaly then a newline with only the word "end" like so:

begin 644 photo.jpg
-encoded image-
end

The script looks for that first line in that order so as not to confuse it
with the word "begin" showing up somewhere else in the message. Here is
the particular line of code that searches for that:

if (preg_match("/^begin\s+[0-9][0-9][0-9]\s+(.+?)\s*\r?\n/m", $body))

The following seems to work for me.

<?php

$body = "

begin 644 photo.jpg
-encoded image-
end

";

if ( preg_match("/begin\s+[0-9]+\s+.+/", $body, $matches) ) {
	echo "found my pattern";
	print_r($matches);
}

?>

Is this inside a loop that you are scanning each line of the message? If not, I am guessing that it was your '^' that told the regex to match from the beginning of the string.



The problem I'm running into is with spaces in the file name. For example,
if it starts with this:

begin 644 a_nice_photo.jpg


it works just fine, decodes the image and places it below the text of the
message. But if the line looks like this:

begin 644 a nice photo.jpg

with spaces in the filename, the script seems to stop looking after the
"a", thinks this is just normal text in the message and doesn't decode the
image. This results in the raw UUEncoded text showing up where the image
should.

I'm stumped. Any ideas?

-Allen



--

DeadTOm
http://www.mtlaners.org
deadtom@xxxxxxxxxxxx
A Linux user since 1999.



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux