Re: Pattern Matching / Formatting
| From: | Lars Torben Wilson | Date: | Mon, 16 Oct 2000 21:24:39 +0000 |
| Subject: | Re: Pattern Matching / Formatting | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20467@lists.php.net to get a copy of this message | ||
Dan Wright writes:
> Greetings all,
>
> Looking for a way to search for all instances of the following pattern:
>
> snip>>>
> end of a sentence in a paragraph.
>
> Headline
>
> Beginning of text in the next paragraph. Etc. Etc. Etc.
> <<<end snip
>
> where it looks like this to probably ereg_replace.
>
> snip>>>
> end of a sentence in a paragraph.LINE_BREAK
> BLANK_LINE-LINE_BREAK
> HeadlineLINE_BREAK
> BLANK_LINE-LINE_BREAK
> Beginning of text in the next paragraph. Etc. Etc. Etc.
> <<<end snip
>
> I want to make what's in Headling bold and that could be any pattern of
> letters, numbers, etc.
>
> Thought one of you may have developed something that will do this.
>
> Something like this:
> $formatted_variable = ereg_repace("*\n\w\n","*\n\w\n<b>",$variable);
> $formatted_variable = ereg_repace("\n\w\n*","<\b>\n\w\n*",$variable);
Those are perl regexps. You'll want to either use the preg_*()
functions or read the ereg*() docs to find the POSIX syntax.
> Thanks in advance,
> Dan
Here's a very quick-and-dirty solution:
preg_replace("/(\n\n)(.*?)(\n\n)/", '\1<b>\2</b>\3', $text);
It doesn't check for the beginning of the text, so if the first item
in the text is a headline, you'll either need to ensure that it has 2
newlines at the beginning, or test for that in the regex. The above
just bolds any text which has 2 newlines on either side.
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+