Re: [PHP] Adding text before last paragraph

2007-08-28 Thread Dotan Cohen
On 28/08/07, Brian Rue [EMAIL PROTECTED] wrote: Sure, I'll break it apart a little: Er, wow, thanks. Lots of material here... '{(?=p(?:|\s)(?!.*p(?:|\s)))}is' $regex = '{' . // opening delimeter '(?=' . // positive lookahead: match the beginning of a position

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Dotan Cohen
On 27/08/07, Richard Lynch [EMAIL PROTECTED] wrote: On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote: I have a string with some HTML paragraphs, like so: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p; I'd like to add an image before the last paragraph. I

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Brian Rue
Dotan, try this: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p; $story = preg_replace('{(?=p(?:|\s)(?!.*p(?:|\s)))}is', pnew paragraph goes here/p\n, $text); This matches a position that has an opening p tag (with or without parameters), which is NOT followed

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Dotan Cohen
On 27/08/07, Brian Rue [EMAIL PROTECTED] wrote: Dotan, try this: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p; $story = preg_replace('{(?=p(?:|\s)(?!.*p(?:|\s)))}is', pnew paragraph goes here/p\n, $text); This matches a position that has an opening p tag

RE: [PHP] Adding text before last paragraph

2007-08-27 Thread Brian Rue
-general@lists.php.net Subject: Re: [PHP] Adding text before last paragraph On 27/08/07, Brian Rue [EMAIL PROTECTED] wrote: Dotan, try this: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p; $story = preg_replace('{(?=p(?:|\s)(?!.*p(?:|\s)))}is', pnew paragraph goes

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Richard Lynch
On Mon, August 27, 2007 1:46 am, Dotan Cohen wrote: On 27/08/07, Richard Lynch [EMAIL PROTECTED] wrote: On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote: I have a string with some HTML paragraphs, like so: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p;

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Richard Lynch
On Mon, August 27, 2007 5:45 pm, Dotan Cohen wrote: Thank you Brian. This most certainly works. I'm having a very hard time decyphering your regex, as I'd like to learn from it. I'm going over PCRE again, but I think that I may hit google soon. Thank you very, very much for the working code.

[PHP] Adding text before last paragraph

2007-08-26 Thread Dotan Cohen
I have a string with some HTML paragraphs, like so: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p; I'd like to add an image before the last paragraph. I know that preg_replace can replace only the first n occurrences of a string, but how can I replace the _last_

Re: [PHP] Adding text before last paragraph

2007-08-26 Thread Richard Lynch
On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote: I have a string with some HTML paragraphs, like so: $text=pFirst paragraph/p\npMore text/p\npSome more text/p\npEnd of story/p; I'd like to add an image before the last paragraph. I know that preg_replace can replace only the first n