Extracting data from remote HTML files without the use of regular expressions
You may have noticed that esnipe.com has started charging for their service. Fair enough. But I hate the thought of paying for something I can program myself. I think this is called righteous indignation, thus the birth of http://cniper.com
I am a graphics guy by day, and so knew that to create an auction sniping site would be a challenge. The toughest part would be extracting the data about the auction from ebay's pages. A little source code viewing quickly revealed ebays bidding system protocols. They are very simple.
To place a bid on ebay you need to send the obvious variables, like username, password, maximum bid, quantity and auction item number. But there is another variable called "key". It is sent as a hidden tag from the login screen after you have declared your maximum bid on actual item viewing page.
This hidden "key" value is a string of characters like "$1$27216251$KIZTwRTWLf5xlqtnrp0Oh1" The only consistent thing I could find was the presence of "$" at common locations. Even after reading Dario Gomes' excellent introduction to regular expressions, I was against a wall. What would happen if a "$" appeared ahead of the hidden tag in the page and tricked my code into capturing something like "$Rare$Fossilized13thcenturyRockfishSkeleton".
Lines 1 and 2 request the bid confirmation screen from ebay with an http fread() command. The page is assigned to a variable.
In line 3, I explode that variable with the separator "key value=". This leaves $key with everything before the tag, and $key with everything following HTML text "key value="
We can forget about $key, it contains the rock fish skeleton. In line 4 we apply the explode() command one more time to $key but this time using the ">" that closes the hidden HTML tag. Voila! we are now left with $clean_key being the buried jem needed to make the cniper.com site work it's magic.
To send bids, we construct the appropriate HTTP call with the variables retrieved from ebay's servers and wham! bids are placed while you sleep. PHP rocks!