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
https://forums.phpfreaks.com/topic/181219-solved-hmm/#findComment-956051
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
https://forums.phpfreaks.com/topic/181219-solved-hmm/#findComment-956111
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.