![]() |
Building an array of matches...
I want to take a page of HTML and put everything in paragraph tags into an array. So far I've failed, obviously... can this be done using a regular expression match easily enough, or is there a better way? This is the short piece of code I've been doing the test with so far;
PHP Code:
*!* |
Hmm, feeling a little silly now, I changed it to
PHP Code:
|
You're definitely going down the right path with the regular expressions -- but what precisely are you trying to do, just get everything between the 2 P tags? How about something like the following:
php Code:
|
Why not use DOM in this instance, it will provide a far more reliable means of grabbing the paragraph elements rather than trying to delve into the intricacies of a suitable regular expression.
For example: PHP Code:
|
Yeah, everything between an opening and closing P including other tags, etc. So that the following,
HTML Code:
<p>Fusce porta pede nec eros. Maecenas ipsum sem, interdum non, aliquam vitae, interdum nec, metus. Maecenas ornare lobortis risus. Etiam placerat varius mauris.</p> |
Worked out WildHoney's regex a bit further. Now also allows newlines inside p elements, as well as html attributes.
Code:
#<p\b[^>]*+>(.+?)</p>#is |
Salathe: I'll look more into that - it grabs the elements and everything in between them though, or does it just go through and match the elements themsevles?
Geert: Thank you, I've actually gotten slowed down working on the design again and less on the coding, but I should get back into it in the next day or two here and I'll give that a try. |
| All times are GMT. The time now is 03:50 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0