finding number colse to the 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

finding number colse to the symbol

Post by avukadomusic »

<?php
$url = 'www.somesite/somepage';

$raw = file_get_contents($url);

preg_match('/\w(\d*).*?\$/',$raw,$matches);


echo $matches;
?>
this is what I tried for now
I just get "array" printed

in a given external website I need the closest number to the first appearance of the symbol $
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: finding number colse to the symbol

Post by Mark Baker »

You will get that message if you try to echo an array

try

Code: Select all

print_r $matches;
instead
avukadomusic
Forum Newbie
Posts: 6
Joined: Fri Jun 12, 2009 3:20 am

Re: finding number colse to the symbol

Post by avukadomusic »

it seems like print_r is not a known php word
I get error unexpected T_VARIABLE for this
if you meant print_r () I tried it and got nothing
print_r ($matches);

I also tried regular print with result just like echo
I tried addind [0] or [1] for $matches
then I get nothing
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: finding number colse to the symbol

Post by Mark Baker »

avukadomusic wrote:it seems like print_r is not a known php word
I get error unexpected T_VARIABLE for this
if you meant print_r () I tried it and got nothing
print_r ($matches);
mea culpa, I meant print_r()

At the very least, this should display an empty array.
If you're getting absolutely nothing displayed when you print_r($matches), then the problem is probably in your regular expression
avukadomusic
Forum Newbie
Posts: 6
Joined: Fri Jun 12, 2009 3:20 am

Re: finding number colse to the symbol

Post by avukadomusic »

my regular expression is what I wrote above
why doesnt it work?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: finding number colse to the symbol

Post by Mark Baker »

avukadomusic wrote:my regular expression is what I wrote above
why doesnt it work?
Pass
Knowing the type of data in $raw that you are parsing might help
Post Reply