scraping and preg_matching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
avukadomusic
Forum Newbie
Posts: 6
Joined: Fri Jun 12, 2009 3:20 am

scraping and preg_matching

Post by avukadomusic »

here is my code with problems:

$url = 'somesite/somepage';

$str = file_get_contents($url);

preg_match('/[0-9]\w(\d*). ?\$/',$str,$matches);

print_r($matches[0]);

the goal is to type in any webpage and get its source code into
$str and then find the first appearance of the symbol $ in the string
and return only the number closest to that symbol after it

1.is there something like screenscrape that not gives me the pictures and layout , just the source code so I can put it in a string like text ?

2.when I replace the "$str = file ..." with
"$str = 'hgfghfgh 7656575 ghfghf 160 $ 600 hfgcgh 340 $ 134 gffg$'"
I get "160 $" but I want only the nomber after the first $ returned and thats it. how should the preg_match be written? ( for example from this string I wanted '600' without $)
Post Reply