For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2005 > Re: Subject: how do i fetch some text









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Subject: how do i fetch some text
Neil Smith [MVP, Digital media]

2005-05-30, 3:55 pm

At 04:51 29/05/2005 +0000, you wrote:
>Message-ID: <02.10.02217.F0449924@pb1.pair.com>
>To: php-db@lists.php.net
>Date: Sun, 29 May 2005 09:54:50 +0530
>From: chintan <chintanonnet@hotmail.com>
>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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com