• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

PHP script question

Yoblad

[H]ard|Gawd
Joined
Jul 24, 2000
Messages
1,060
I'm new to php (programming in general) and am looking for something that will "grep" certain strings of websites and display the results in a file (or email them to me) if they change. Like if directv changes their pricing or something. Eventually I want to keep tabs on pricing options for multiple companies and update them to a mysql database.
 
In perl their are good modules for doing things like that based on the LWP code. PHP has curl interfaces that can be compiled in, I'd start digging through their documentation on the curl extension and see if that can help.
 
Generally, what you're trying to do is known as "scraping", and it's not always easy to do. PHP is not the environment one would ordniarly do it in, either, though there's no reason you couldn't. I'm not a fan of Perl, but I've seen this tutorial before, and it looks promising. If you're set on doing it in PHP, you'll want to check out the curl library (to get the contents of the web page) and the various regexp libraries to try to find what you want in the page.

Usually the strategy is to look for some particular text or tags that identify the data you're looking for. If you're lucky, you get something like <span class="price">$3.14</span>, which is very easy to search for. More likely you'll just get some generic tags like <td><b>$15.92</b></td> that won't give you much context and may not be unique in the page.
 
Of course, you may also come across a terrible site like this that has all of its prices rendered as images. Scraping something like that would be vastly more difficult. For something like this, it's a little easier. If you have access to a Unix/Cygwin prompt, try this:
Code:
curl -s "http://www.directv.com/DTVAPP/learn/Packages_TotalChoice.dsp" | grep "local channels for just" | sed -e 's/.*\$//' -e 's/ .*$//'
When I run it, the output is "41.99", which is basically what you're trying to get. Each of those commands has a rough analog in PHP. Hope that helps.
 
That's kind of what I'm trying to do right there. I've been playing around with preg_match and file_get_contents and am getting very close. I'm just having a problem telling preg_match what I want to search for.

take a look at this page for example: http://www.autozone.com/servlet/UiB...ervice/shopping_at_autozone/free_shipping.jsp

I want to isolate "at least" and the $ in the price but keep the actual numbers dynamic. like use a wild card or something. I can get it to kind of do that by just going something like [0-9]+[0-9]+[.]+[0-9]+[0-9]$ but there has to be a better way. I know is this is really simple for a web programmer to do but I just need a real example of what I'm trying to do so I can figure this out.

Thanks.
 
Back
Top