prometheuzz wrote:ZaphodQB wrote:
...
This does not work, it raises an error during parsing.
Parse error: syntax error, unexpected '<' in /home/a2426477/public_html/test.php on line 2
It works fine. With the following input:
Code: Select all
------_=_NextPart_002_01C8B165.D1A0F25B
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
The original start of the email text
I get the following output:
Code: Select all
------_=_NextPart_002_01C8B165.D1A0F25B
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
The original start of the email text
Perhaps you left the "#!/usr/bin/php" part when copy-pasting it? That line only needs to stay if you're executing it from the shell (and the executable 'php' resides in #!/usr/bin/)
And in case the <<< is causing problems, you can try:
Code: Select all
<?php
$text = "------_=_NextPart_002_01C8B165.D1A0F25B
Content-Type: text/plain;
charset=\"us-ascii\"
Content-Transfer-Encoding: quoted-printable
The original start of the email text";
print preg_replace('/(Content-Transfer-Encoding:.*?\n)\n+/', "$1\n\n", $text);
?>
I got it working, but, and maybe I am missing something, it is not really changing the file and inserting anything, the text remains the same.
Even when adding a line of text to the replacement string like so
Code: Select all
<?php
$text = <<< BLOCK
------_=_NextPart_002_01C8B165.D1A0F25B
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
The original start of the email text
BLOCK;
print "<pre>".preg_replace('/(Content-Transfer-Encoding:.*?\n)\n+/', "$1\n\nMy line of text", $text)."</pre>";
?>
the output is still unchanged
------_=_NextPart_002_01C8B165.D1A0F25B
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
The original start of the email text
and, playing with it to try and make it match starting at "Content-Type: text/plain;" which is what I need because that is the thing I am looking for in order to be sure I am entering the text in the correct part of the multi part email, fails to match more then the "Content-Type: text/plain;" line.
Let me try to explain again;
emails can be multi part containg both plain text and html portions.
I want to be able to regex the entire body of the email and
1. find the header which says this is the plain text portion
2. find the end of that header/start of the actual message (by the specs that is 2 carriage returns)
3.
insert a line of text directly after those 2 carriage returns.
Also;
I want to be able to regex the entire body of the email and
1. find the header which says this is the html portion
2. fin this section I need to go a little deeper in to the message and find the <body> tag
3.
insert a line of text directly after that <body> tag.
So it is imperitive that the match starts at the Content-Type header field, in order to know which part of the email I am dealing with, and match all the way to the 2 carriage returns and or the <body> tag, inclusive. Once I have extracted a copy of that data I can append my line of text and then replace the existing "several lines" with the new data which has my
new line of text on the end.