Re: Subject: how do i fetch some text

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 04:51 29/05/2005 +0000, you wrote:
Message-ID: <02.10.02217.F0449924@xxxxxxxxxxxx>
To: php-db@xxxxxxxxxxxxx
Date: Sun, 29 May 2005 09:54:50 +0530
From: chintan <chintanonnet@xxxxxxxxxxx>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Subject: how do i fetch some text

how do i fetch some text from a webpage for some generated field?

You would have to retrieve the whole web page. Look up fopen(url) in the PHP manual, and then the related fgets() and fclose() functions. Using these you can read the HTML of the web page into a string or array, and use regular expressions such as preg_match() to extract the string of numbers after the string "score" which is inside your "generated field".

like i want to fetch a score line from a sport site in which the line says "score"? actually i want to fetch an IP from my ISP's page which displays it with my user name.

Actually ? You mean this was a bogus example and you are wasting our time ?

Why not say what you *actually* want. If you want to retrive your IP addresss, then write code to do that. But it's a waste of time to go to your ISPs web page, to extract that, when you can do it as easily yourself.

This code returns your current IP address :

<?php
function getUserIPAddr() {
        global $_SERVER;
        $privip=false;
        $remote=$_SERVER["REMOTE_ADDR"];

$comes_from=array("HTTP_VIA", "HTTP_X_COMING_FROM", "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED","HTTP_COMING_FROM", "HTTP_FORWARDED_FOR",
                                        "HTTP_FORWARDED");
//      By preference, replace the remote IP with the proxied-for IP
        foreach ($comes_from as $value) {
if (ereg("^([0-9]{1,3}\.){3,3}[0-9]{1,3}",$_SERVER[$value],$remote_temp)) { $remote=$remote_temp[0]; // Fish out IP match if ereg returns a value
                }
        }

//      Check range against private IP addresses
        if (ereg("^192\.168\.[0-9]{1,3}\.[0-9]{1,3}",$remote,$remote_temp)) {
                $privip=true;
                $remote=$_SERVER["REMOTE_ADDR"];
        }

        if (ereg("^172\.([0-9]{1,3}\.){2}[0-9]{1,3}",$remote,$remote_temp)) {
//      Extra check on range
                if ($remote_temp[1]>=16 && $remote_temp[2]<32 ) {
//      is in class B private address range
                        $privip=true;
                        $remote=$_SERVER["REMOTE_ADDR"];
                }
        }

        if (ereg("^10\.([0-9]{1,3}\.){2}[0-9]{1,3}",$remote,$remote_temp)) {
                $privip=true;
                $remote=$_SERVER["REMOTE_ADDR"];
        }

        return $remote;
}       //      End function getUserIPAddr()
?>

Cheers - Neil

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux