PDA

View Full Version : PHP match functions


phatmonkey
03-17-2004, 02:52 PM
Ok, what I am basically trying to do is to get an amount of hits from an external html page, and putting it into a variable. I know a piece of unique start code in front of the number, and a some code that goes after the number. I came up with this:


// Open the page
$handle = fopen($hitsurl,"r");

// Read it and put it into a variable
$hitpage = fread($handle,100000);

// Sort out the codestart/ends to take out anything that affects the code
$codestartfixed = str_replace("/", "\/", $codestart);
$codeendfixed = str_replace("/", "\/", $codeend);

// Look through the page to find the number between the start and end code
preg_match("/$codestartfixed(.*)$codeendfixed/isU",$hitpage,$match);

echo " - $match[0] hits";



$codestart = code in front of number
$codeend = code after number
$hitsurl = the url of the page
Obviously assuming its smaller than 100k.

But this echos "- hits". What have i done wrong?

jemfinch
03-17-2004, 03:54 PM
My guess is that you're using the preg_match function wrong. Are you sure it doesn't *return* a match, instead of taking one as an argument?

What you did wrong, of course, is to use PHP in the first place :)

Jeremy

bdl
03-17-2004, 11:09 PM
What you did wrong, of course, is to use PHP in the first place


Whats wrong with PHP? It's not the answer to everything, but it has its purpose. What would you suggest? And why wouldn't you suggest a better alternative rather than leave a snide remark?

stuka
03-18-2004, 10:14 AM
bdl: don't encourage jemfinch by taking his bait! His suggestion, of course, would be Python (note the sig). And I assure you, if you ask him for a suggestion, he'll offer at least one ;). As for the snide remarks - well, they just come as a fun bonus.

bdl
03-18-2004, 11:39 AM
Stuka> Thanks for the tip; it's obviously a troll post meant to waste people's time rather than actually help someone, but I like to challenge others to explain themselves anyway. ;-)

phatmonkey> have you made any progress with your script? I can't quite make out what you've got going on there, if you're still having problems, post some more details as to what you're trying to accomplish, I'm sure there's an easier solution.