I'm having difficulty returning the first paragraph of a string called
$summary. (Usually this string will only be one paragraph, but it might
contain more than one paragraph. Current data has one occurrence of a
two-paragraph $summary.)

Here's how I process when I want multiple paragraph display. This
successfully generates the necessary HTML:

$summary = trim($summary);
$summary = ereg_replace("\r", "", $summary);
$summary = ereg_replace("\n\n", "</p><p>", $summary);
$summary = ereg_replace("\n", "<br/>", $summary);

Here's what I thought would work to give me the first paragraph only:

$summary = trim($summary);
$summary = ereg_replace("\r", "", $summary);
$summary = preg_replace("/^(.*)\n/", "\1", $summary);

But for occurrences of $summary with two paragraphs, the above returns the
second paragraph (without the first).

The only way I can return the first paragraph for a two paragraph $summary
is with:

$summary = trim($summary);
$summary = ereg_replace("\r", "", $summary);
$summary = preg_replace("/(.*)$/", "\1", $summary);

This gives me the first paragraph as desired (although I don't understand
why!), but returns nothing for occurrences of $summary having only one
paragraph.

I also tried this:

$summary = trim($summary);
$summary = ereg_replace("\r", "", $summary);
$summary = ereg_replace("\n\n", "</p><p>", $summary);
$summary = preg_replace("#(.*)</p><p>#", "\1", $summary);

This also returns only the second paragraph. Can anyone point out what I'm
doing wrong, or suggest another approach?

TIA

--
Lowell Allen


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

Reply via email to