Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread John Campbell
On Wed, Jan 12, 2011 at 10:55 PM, Rob Marscher wrote: >> On Wed, Jan 12, 2011 at 9:30 AM, Jim Yi wrote: >>> This problem is much better suited for an XML parser > On Jan 12, 2011, at 9:39 AM, Randal Rust wrote: >> I will have to try this out, because I am not sure that the approach I >> was takin

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Chris Snyder
On Wed, Jan 12, 2011 at 9:30 AM, Jim Yi wrote: > This problem is much better suited for an XML parser, and it makes your code > more readable as well.  Code snippet: > $dom = new DOMDocument(); > $dom->loadHTML($txt); > $items = $dom->getElementsByTagName('p'); > foreach ($items as $paragraph) { >

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Dan Cech
On 1/12/2011 10:55 AM, Daniel Convissor wrote: On Wed, Jan 12, 2011 at 10:00:49AM -0500, justin wrote: /]*)?>.*?<\/p>/s Uh, what's the ? doing there after the .* in the middle? The .* is all that's needed. Ungreedy match. Dan ___ New York

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Daniel Convissor
On Wed, Jan 12, 2011 at 10:00:49AM -0500, justin wrote: > /]*)?>.*?<\/p>/s Uh, what's the ? doing there after the .* in the middle? The .* is all that's needed. --Dan -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y data intensive web and database progra

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread justin
On Wed, Jan 12, 2011 at 8:24 AM, Randal Rust wrote: > I am admittedly not very good with regular expressions. I am trying to > pull all of the paragraphs out of an article, so that I can create > inline links. Here is my script: > > $blockpattern='/]*>.*?<\/p>/'; > $blocks=preg_match_all($blockpat

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
On Wed, Jan 12, 2011 at 9:55 AM, Rob Marscher wrote: > I seem to remember having problems when I was using the DomDocument on rss > feeds that were submitted by users and not under my control. Thanks for the tip. In this case, it's not an RSS feed, and I have control over the content, so I can

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Rob Marscher
> On Wed, Jan 12, 2011 at 9:30 AM, Jim Yi wrote: >> This problem is much better suited for an XML parser On Jan 12, 2011, at 9:39 AM, Randal Rust wrote: > I will have to try this out, because I am not sure that the approach I > was taking will work. I seem to remember having problems when I was u

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
On Wed, Jan 12, 2011 at 9:30 AM, Jim Yi wrote: > This problem is much better suited for an XML parser, and it makes your code > more readable as well.  Code snippet: > $dom = new DOMDocument(); > $dom->loadHTML($txt); > $items = $dom->getElementsByTagName('p'); > foreach ($items as $paragraph) {

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Donald J. Organ IV
Try: $blockpattern='/]>.*?/m'; Notice the m after the last / this says it can span multiple lines - Original Message - From: "Randal Rust" To: "NYPHP Talk" Sent: Wednesday, January 12, 2011 9:06:44 AM Subject: Re: [nyphp-talk] Regex for

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Jim Yi
This problem is much better suited for an XML parser, and it makes your code more readable as well. Code snippet: $dom = new DOMDocument(); $dom->loadHTML($txt); $items = $dom->getElementsByTagName('p'); foreach ($items as $paragraph) { echo $paragraph->nodeValue; // You can also manipu

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Rob Marscher
On Jan 12, 2011, at 9:20 AM, Dan Cech wrote: > Good call, I missed the multiple-line thing. In this situation though you'd > actually want /s Thanks for sharing the difference between /s and /m. I never noticed that. Leaned something new this morning.

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
On Wed, Jan 12, 2011 at 9:20 AM, Dan Cech wrote: > Good call, I missed the multiple-line thing.  In this situation though you'd > actually want /s like: > > $blockpattern='/]*>.*?<\/p>/s'; That's it. I tried it with /m, but it gave me 0 results. Replaced with /s and now I have the array of 33 pa

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Dan Cech
On 1/12/2011 9:00 AM, Donald J. Organ IV wrote: $blockpattern='/]>.*?/m'; Notice the m after the last / this says it can span multiple lines Good call, I missed the multiple-line thing. In this situation though you'd actually want /s like: $blockpattern='/]*>.*?<\/p>/s'; From the ma

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
On Wed, Jan 12, 2011 at 8:55 AM, Dan Cech wrote: > Shouldn't the expression be: > > $blockpattern='/]*>.*?<\/p>/'; > > I removed the * after the first p. Trying to work my way through the expression, to see where it fails. If I use this: $blockpattern='/]*>.*?/'; It returns 116 matches, but if

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
On Wed, Jan 12, 2011 at 8:58 AM, Randal Rust wrote: > I'm sure that could be the case, but I figured out the problem, Nuts. I spoke too soon. It didn't work. -- Randal Rust R.Squared Communications www.r2communications.com www.facebook.com/r2communications 614-370-0036 ___

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
On Wed, Jan 12, 2011 at 8:55 AM, Dan Cech wrote: > Shouldn't the expression be: > > $blockpattern='/]*>.*?<\/p>/'; > > I removed the * after the first p. I'm sure that could be the case, but I figured out the problem, literally just as your reply hit my inbox. The paragraphs had line returns in

[nyphp-talk] Regex for P Elements

2011-01-12 Thread Randal Rust
I am admittedly not very good with regular expressions. I am trying to pull all of the paragraphs out of an article, so that I can create inline links. Here is my script: $blockpattern='/]*>.*?<\/p>/'; $blocks=preg_match_all($blockpattern, $txt, $blockmatches); This returns 0. However, if I try

Re: [nyphp-talk] Regex for P Elements

2011-01-12 Thread Dan Cech
On 1/12/2011 8:24 AM, Randal Rust wrote: I am admittedly not very good with regular expressions. I am trying to pull all of the paragraphs out of an article, so that I can create inline links. Here is my script: $blockpattern='/]*>.*?<\/p>/'; $blocks=preg_match_all($blockpattern, $txt, $blockmat