The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. February 12, 2012, 07:43:02 AM

Login with username, password and session length


Pages: 1 [2]
  Print  
Author Topic: stupid regex question: all or nothing  (Read 3039 times)
nutballs
Administrator
Lifer
*****
Online Online

Posts: 5604


Back in my day we had 9 planets


View Profile
« Reply #15 on: October 25, 2008, 09:21:52 AM »

yes, strip tags is faster. however, I have also had less than predictable results from that as well.

plus its a personal pref. I don't like using magic voodoo functions that I get surprised by when they get "upgraded" later on. It has happened too many times in thepast to me.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Bompa
Administrator
Lifer
*****
Online Online

Posts: 509


View Profile
« Reply #16 on: October 25, 2008, 05:09:16 PM »

Ah cool thanks Bompa,
I thought ? meant that the group or sign in front of ? can only occur once.
So what if I whant everything in before the third </div> tag ?
Is it /<div(.*){3}</div>/s  Huh?

The ? does mean 0 or 1 times when it is used as a quantifier.

Anyways, you said "selected sites", so you will know what type of html that
you have to deal with. 

The way I usually deal with this situation is with a while loop.

Code:
$string =<<"here";
<div id1="content">
<p>blabla content bla</p>
</div>
<div id2="nextcontainer>
<p>blabla</p>
</div>
<div id3="nextcontainer>
<p>blabla</p>
</div>
<div id4="nextcontainer>
<p>blabla</p>
</div>
here

while($string =~ /<div(.*?)<\/div>/sg) {
  ++$divcounter;
  if($divcounter == 2) { print "$1\n"; }
}

This prints the 3rd div cuz the counting starts at zero.

The g modifier needs to be there at the end of the regex.

good luck,
Bompa



Logged

"Everything that can be counted does not necessarily count; everything that counts cannot necessarily be counted." -- Albert Einstein
Pages: 1 [2]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!