find the closest number to symbol

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

find the closest number to symbol

Post by avukadomusic »

hi I need a code to find the closest number to the symbol $ in a given url's source code
for example

http://www.somesite/somepage
the source code of this page has some prices:

code... code... code...code... code... code...
160 $
code... code... code...code... code... code...
210$
code... code... code...code... code... code...
ets'

I want a code that would return just the first number that is near the $ sign

thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: find the closest number to symbol

Post by pickle »

A regex might work

(untested):

Code: Select all

$source_code = 'source code of page';
preg_match('/\w(\d*).*?\$/',$source_code,$matches);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
avukadomusic
Forum Newbie
Posts: 6
Joined: Fri Jun 12, 2009 3:20 am

Re: find the closest number to symbol

Post by avukadomusic »

hi , it didn't work
maybe I was not explaining good

I think it is like screen scraping
the data I need in an external website's source code
I want the program to be given a page's address
and it would search the page's source code and giving me the closest number to a given sign like $
the first time $ shows up.
Post Reply