Its driving me mad.

Ok guys this is driving me crazy.
I have done a little php and I like it but I have this problem.
I know how to pass data by url and receive it from the url with GET and POST.
But now I have a url specifically.

If you load this page to browser it will give the current price of silver in $AUD/ ounce However I don’t want to load the page in the browser. I just want to get the price to work with in my own page.
In just html an Iframe will load the URL like so

However if I use php to try to get a value like so

<?php $_GET = ""; echo $_GET; $v1 = $_GET['WeightU']; $v2 = $_GET['Units']; $v3 = $_GET['Metal']; $v4 = $_GET['PurityC']; $v5 = $_GET['CurrencyN']; $v6 = $_GET['PrOzt']; echo "Variable One Value: $v1
Variable Two Value: $v2
Variable Two Value: $v3
Variable Two Value: $v4
Variable Two Value: $v5
Variable Two Value: $v6 "; ?>

It runs ok but will not give me the values it comes back with a list like this .

Variable Two Value: h
Variable Two Value: h
Variable Two Value: h
Variable Two Value: h
Variable Two Value: h

Where in Gods name is it getting all the hs from ???

I don’t want the page loaded in an I fram or a browser I just want the price value to work with .
How can I do this .
Please help O wize ones.

This code is not correct:
[php]$_GET = “”;
echo $_GET;[/php]

$_GET is a global array that contain all the parameters received by script via GET request method.
If you want to get page from remote site, you need to use file_get_contents() function:
[php]$content = file_get_contents(“”);[/php]

This will return you HTML code of given page. If you want to extract price or any other information from this page, you will need to parse it either using regular expressions or using html DOM model.

Ok I thank you for that .
Now it is bringing it back because I used

<?php $content = file_get_contents(""); echo $content; ?>

This prints the whole page.
I just want the price so I guess I will have to learn about
regular expressions and html DOM model

Luck I have plenty time Hey… :stuck_out_tongue:

Here is the code that will extract price from your page:
$content = file_get_contents(‘’);

if(preg_match("~>[\s]*([0-9.]+)[\s]*AUD / Troy Oz~i",$content,$matches)){
echo $matches[1];
echo ‘No matches’;

thank you Owize one.
How on earth was I ever expected to get that .
I dont even understand what you have done but it dose work
But why is it that I upload script and execute with this result.

the price is indeed there but not equal to the actual price in the original page .
Which is displayed in an IFrame as well.

not equal to the actual price in the original page

there are many numbers of the source page. You asked about “price”. The “price” field on the source page shows 38.44 Do not see what is wrong?

Ok now I see it .
What I really wanted was Value of metal price
Can you please help here because I really cant repair your code it is beyond me.
I am still trying to understand it.

No problem. Change this line:
[php] if(preg_match("~>[\s]*([0-9.]+)[\s]*AUD / Troy Oz~i",$content,$matches)){[/php]

to this:
[php] if(preg_match(’~id=“Result”>[\s][\s]([0-9.]+)[\s]AUD[\s]~i’,$content,$matches)){[/php]

This code means that we defined a pattern, based on HTML tags in the source page. The [\s]* means one or more whitespace chars (space, tab, new line), the ([0-9.]+) means that we search string that contains one or more digits 0-9 and/or dot(s). The small i at the end means that our pattern is case insensitive.

You are absolutely brilliant.
I may have never real need of this but I am a silver stacker with 869 ounces on hand.
So one day maybe.
I am also almost 65 years old and trying to learn this stuff at my age is probably not even sensible.
Truth is I would have never understood it Because if there is one thing I have learnt from computers it is just how clever other people really are .
I really thank you for that help.

Code is extracting beautifully now .
Now this number I can work with .
God bless your living sole .

Thanks, nasa :slight_smile:

It is never too late to learn!

Sponsor our Newsletter | Privacy Policy | Terms of Service