Page 1 of 1

finding number colse to the symbol

Posted: Mon Jun 15, 2009 6:39 am
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 $

Re: finding number colse to the symbol

Posted: Mon Jun 15, 2009 7:57 am
by Mark Baker
You will get that message if you try to echo an array

try

Code: Select all

print_r $matches;
instead

Re: finding number colse to the symbol

Posted: Mon Jun 15, 2009 8:11 am
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

Re: finding number colse to the symbol

Posted: Mon Jun 15, 2009 8:19 am
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

Re: finding number colse to the symbol

Posted: Mon Jun 15, 2009 9:15 am
by avukadomusic
my regular expression is what I wrote above
why doesnt it work?

Re: finding number colse to the symbol

Posted: Mon Jun 15, 2009 10:12 am
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