Jump to content

Selecting Email styled blockquotes


Xeoncross

Recommended Posts

Markdown is one of the few markup tools that selects ">blah, blah..." styled old-fashioned email quotes and converts it into HTML blockquotes.

 

I have been trying to do that with PHP but I just can't get it together. So far I have lots of regex patterns that work in regexpal - but not PHP. And I can't figure out why. I have used the /.../m and other modifiers yet it won't cache the string right.

 

(^>([^\n]+(\n|$)+?)+?)
^>(([^\n]+\n)+?)
^\>((.|\n)+?)\n\n

 

<this is some text >followed by an invalid quote

>this is a real quote

> this is a quote
that is broken up
across lines


>Another quote
>with a starting
>> sign

Just plain text
>End quote

 

 

The goal would be to catch all lines that start with a ">" followed by EVERYTHING upto two returns "\n\n". That should be a standard quote.

 

Link to comment
https://forums.phpfreaks.com/topic/163157-selecting-email-styled-blockquotes/
Share on other sites

If I understand correctly, you mean something like this?

 

example:

$str = <<<EOD
<this is some text >followed by an invalid quote

>this is a real quote

> this is a quote
that is broken up
across lines


>Another quote
>with a starting
>> sign

Just plain text
>End quote
EOD;

preg_match_all('#^(>[^>]+)#m', $str, $matches);
$matches[1] = array_map('trim', $matches[1]);
echo '<pre>'.print_r($matches[1],true);

 

Output:

Array
(
     => >this is a real quote[1] => > this is a quote
that is broken up
across lines
    [2] => >Another quote
    [3] => >with a starting
    [4] => >End quote
)

Thanks, that is along the same idea. But I don't want each new line starting with a ">" to be a new blockquote. If you look back at the old emails there were often many lines in replies / forwards that started with a ">". So I want all of those (up to two line brakes) to be counted as a single blockquote. With your code I would have a new blockquote for each line which won't work.

 

Thanks Joe

>Joe wrote:
>Sent you your check
>-Joe

 

 

To allow laziness, I also want to just look for something that starts with a ">" and goes to two line brakes (\n\n) even if those other lines don't start with a ">".

 

Thanks Joe

>Joe wrote:
Sent you your check
-Joe

-Sam (outside of the blockquote)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.