faqts : Computers : Programming : Languages : PHP : Common Problems : Regular Expressions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 9 people (44%) answered Yes
Recently 4 of 9 people (44%) answered Yes

Entry

Looking for a way to grab a page from the web. Search for string "Hits", then display result (eg 2525) if page showed "Hits: 2525"

Dec 22nd, 2001 09:39
Kurtis Kopf,


This is the best way that I can think of...


if(ereg("([Hh][Ii][Tt][Ss] *: *)([0-9]+)",$string,$myvars))
     echo $myvars[2];

this searches the $string variable for several variations 
of "Hits:0123" and returns the first match into $myvars. The first 
encapsulation of () becomes $myvars[1], the second becomes $myvars[2].