Jump to content

[SOLVED] Hmm...


darkvengance

Recommended Posts

Then yes, there are several things wrong with your pattern.

 

a.) you use the ^ and $ which checks start and end respectively. They are used when you wish to match a string against a pattern not when you wish to search a string for sub patterns.

b.) the . doesn't match newline characters by default and it seems likely being HTML there there will be some between the various characters/tags.

c.) if you are trying to grab all divs you should surely be looking for </div> at some point in your pattern.

d.) why do you have <a in your pattern if you simply wish to grab the divs from the page?

e.) why put capture groups around <div> and <a. Since they are fixed strings there's really no point.

 

Other than that, your good to go  :D

Link to comment
Share on other sites

Just so that I don't sound like a complete downer, here's a couple of tips (much of which can be intimated from my previous post). Scrap the ^ and the $, they aren't needed in this task. Use the 's' modifer, this will make the . match newline characters. You should probably also use the 'i' modifier to make the pattern case insensitive. Off the top of my head, here's a very basic example of achieving the task...

 

'#<div>(.*?)</div>#is'

 

...but this will encounter problems with nested <div>'s. You might be better off using some sort of document model. Such as DOMDocument.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.