470,874 Members | 1,859 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

Reading a file

Hi,
I have a Temperature sensor with internal web server that provide the data
in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that kind
of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....

Is there a simple way of achieving this?
thanks for your help.
VooDoo
Jul 17 '05 #1
29 2534
VooDoo wrote:
Hi,
I have a Temperature sensor with internal web server that provide the data
in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that
kind of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....

Is there a simple way of achieving this?
thanks for your help.
VooDoo


Hi Voodoo,

1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);

3) close the file.
fclose($handle);

4) explode the var with | as seperator. (check www.php.net, find explode)
It will return an array of all elements.
$myElements = explode("|", $myTempLine );

5) store them in your database.

Good luck,

Regards,
Erwin Moller

Jul 17 '05 #2
.oO(VooDoo)
I have a Temperature sensor with internal web server that provide the data
in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that kind
of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....


$data = file_get_contents('http://192.168.10.220/temp');
preg_match_all('#probe (\d+)\|([^|]+)#i', $data, $m);

PHP5:
$result = array_combine($m[1], $m[2]);

PHP4:
$result = array();
for ($i = 0; $i < count($m[1]); $i++) {
$result[$m[1][$i]] = $m[2][$i];
}

The result:

Array
(
[1] => 82.2
[2] => 80.8
[3] => -99.9
[4] => -99.9
)

HTH
Micha
Jul 17 '05 #3
Hi guys!
Thanks a lot for your help i will try all your solution and see wich one i
like the most.
I really appreciated your fast help.
Rgds,
VooDoo
"Michael Fesser" <ne*****@gmx.net> a écrit dans le message de
news:c2********************************@4ax.com...
.oO(VooDoo)
I have a Temperature sensor with internal web server that provide the datain a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that kindof reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....


$data = file_get_contents('http://192.168.10.220/temp');
preg_match_all('#probe (\d+)\|([^|]+)#i', $data, $m);

PHP5:
$result = array_combine($m[1], $m[2]);

PHP4:
$result = array();
for ($i = 0; $i < count($m[1]); $i++) {
$result[$m[1][$i]] = $m[2][$i];
}

The result:

Array
(
[1] => 82.2
[2] => 80.8
[3] => -99.9
[4] => -99.9
)

HTH
Micha

Jul 17 '05 #4
Hi,
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
Hi,
I have a Temperature sensor with internal web server that provide the data in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that
kind of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....

Is there a simple way of achieving this?
thanks for your help.
VooDoo


Hi Voodoo,

1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);

3) close the file.
fclose($handle);

4) explode the var with | as seperator. (check www.php.net, find explode)
It will return an array of all elements.
$myElements = explode("|", $myTempLine );

5) store them in your database.

Good luck,

Regards,
Erwin Moller

Jul 17 '05 #5
VooDoo wrote:
Hi,
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Shame. :-(
1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);


If you print out the $myTempLine, what do you see?
Is it empty?

Regards,
Erwin Moller
Jul 17 '05 #6
yes...
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
Hi,
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Shame. :-(
1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);


If you print out the $myTempLine, what do you see?
Is it empty?

Regards,
Erwin Moller

Jul 17 '05 #7
.oO(VooDoo)
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Check your php.ini:

Is allow_url_fopen enabled?
Is error_reporting set to E_ALL?

Micha
Jul 17 '05 #8
yes for both.
If i use the url http://192.168.10.220/
wich is the main page for the sensor view the it works....
The page http://192.168.10.220/temp/ only contain this:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
with no html code at all, is that the problem???
The main page is full off html and other code....
Thanks for your help.
VooDoo
"Michael Fesser" <ne*****@gmx.net> a écrit dans le message de
news:t0********************************@4ax.com...
.oO(VooDoo)
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Check your php.ini:

Is allow_url_fopen enabled?
Is error_reporting set to E_ALL?

Micha

Jul 17 '05 #9
VooDoo wrote:
yes...


Ok,

Probably that internal webserver send a lot back. Many lines.
(In my example I expected only one line back.)

Let's check that first by getting the WHOLE response in:

Try this first:
(Straight from http://nl.php.net/manual/en/function.file.php)
$lines = file('http://192.168.10.220/temp');

foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
do you get a response that makes sense?
If so, try to find the linenumber that contains the information you need.

Keep me informed. We'll fix this. :-)

Regards,
Erwin

Jul 17 '05 #10
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a
full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to
fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
yes...
Ok,

Probably that internal webserver send a lot back. Many lines.
(In my example I expected only one line back.)

Let's check that first by getting the WHOLE response in:

Try this first:
(Straight from http://nl.php.net/manual/en/function.file.php)
$lines = file('http://192.168.10.220/temp');

foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n"; }
do you get a response that makes sense?
If so, try to find the linenumber that contains the information you need.

Keep me informed. We'll fix this. :-)

Regards,
Erwin

Jul 17 '05 #11
same thing with thte new code..... :(
"VooDoo" <cr*******@ifrance.com> a écrit dans le message de
news:cf**********@reader1.imaginet.fr...
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a
full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to
fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
yes...


Ok,

Probably that internal webserver send a lot back. Many lines.
(In my example I expected only one line back.)

Let's check that first by getting the WHOLE response in:

Try this first:
(Straight from http://nl.php.net/manual/en/function.file.php)
$lines = file('http://192.168.10.220/temp');

foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}
do you get a response that makes sense?
If so, try to find the linenumber that contains the information you need.
Keep me informed. We'll fix this. :-)

Regards,
Erwin


Jul 17 '05 #12
VooDoo wrote:
same thing with thte new code..... :(
"VooDoo" <cr*******@ifrance.com> a �rit dans le message de
news:cf**********@reader1.imaginet.fr...
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a
full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to
fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...
Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say: No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9


Question: How do you know this?

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}

produces nothing?

And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

Because when that is the case, PHP somehow cannot grab the output produced
by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}

Does that produce many lines of code?

Regards,
Erwin Moller
Jul 17 '05 #13
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
same thing with thte new code..... :(
"VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
news:cf**********@reader1.imaginet.fr...
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...
Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say: No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/
Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; }

produces nothing? Yes ! And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true? YES Because when that is the case, PHP somehow cannot grab the output produced
by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; }

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for
them...
But as far as i get the right content on that page: 192.168.200.10/temp i
imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Jul 17 '05 #14
VooDoo wrote:
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a �rit
dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
> same thing with thte new code..... :(
> "VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
> news:cf**********@reader1.imaginet.fr...
>> Thanks erwin.
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>> nothing else, no html code at all.
>> If i use the default page of the server (192.168.10.220) where there
>> is a >> full of other caracter, then it works fine...
>> the constructo said that the page192.168.10.220/temp has been designed to >> fit custom application, and it just provided the value of the
>> different probe...
>> i try out your new code and let you know...


Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9


Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for
them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10 first.

Do you get an answer?

Regards,
Erwin Moller

Jul 17 '05 #15

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a ?rit
dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:

> same thing with thte new code..... :(
> "VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
> news:cf**********@reader1.imaginet.fr...
>> Thanks erwin.
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>> nothing else, no html code at all.
>> If i use the default page of the server (192.168.10.220) where there
>> is a
>> full of other caracter, then it works fine...
>> the constructo said that the page192.168.10.220/temp has been
designed to
>> fit custom application, and it just provided the value of the
>> different probe...
>> i try out your new code and let you know...

Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10

first.
Do you get an answer?

Regards,
Erwin Moller


Yes i get the page with the result....
weird!
Jul 17 '05 #16
http://195.68.51.202
here you can find the sensor page
if that can you give more ideas...
thanks a lot again for helping me on this
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a ?rit
dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:

> same thing with thte new code..... :(
> "VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
> news:cf**********@reader1.imaginet.fr...
>> Thanks erwin.
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>> nothing else, no html code at all.
>> If i use the default page of the server (192.168.10.220) where there
>> is a
>> full of other caracter, then it works fine...
>> the constructo said that the page192.168.10.220/temp has been
designed to
>> fit custom application, and it just provided the value of the
>> different probe...
>> i try out your new code and let you know...

Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10

first.
Do you get an answer?

Regards,
Erwin Moller

Jul 17 '05 #17
VooDoo wrote:
<snip>
Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10

first.

Do you get an answer?

Regards,
Erwin Moller


Yes i get the page with the result....
weird!


Hi,

Yes, weird.

It seems that PHP cannot handle the content of that internal webserver the
right way.
I have never seen this before.
In my experience PHP is always extremely flexible.

We must be overlooking something.

I am out of options. :-(

I think I go home, and, who knows, tomorrow I'll have a flash or insight.
:-)
Hee, I was getting my coat on when it struck me that MAYBE the response of
the webserver doesn't have an END-OF-LINE.
Suppose it just ends with an END-OF-FILE??

That would explain why the code you tried didn't recognize anything because
it looks for end-of-lines!!

Try file_get_contents("http://192.168.200.10/temp") to see if anything
returns.
Or maybe a socketfunction.
I am unfamiliar with them because I always use file(), so please check
www.php.net for details.

Good luck and keep me informed.
Regards,
Erwin Moller

Jul 17 '05 #18
VooDoo wrote:
http://195.68.51.202
here you can find the sensor page
if that can you give more ideas...
thanks a lot again for helping me on this


Hi,

Great, now you got me addicted to this little problem. :P
*takes coat off*

I'll be back soon. :-)

Regards,
Erwin

Jul 17 '05 #19
.oO(VooDoo)
http://195.68.51.202
here you can find the sensor page


The main page works, but I can't access http://195.68.51.202/temp/ with
a lynx-browser. Web-sniffer also shows nothing:

<http://web-sniffer.net/?url=http%3A%2F%2F195.68.51.202%2Ftemp%2F>

No response ... strange. So I would rather parse the main page to get
the results, shouldn't be too difficult, something like

$data = file_get_contents('http://195.68.51.202/');
preg_match_all('#>([^>]+?) &deg#', $data, $matches);
print_r($matches[1]);

HTH
Micha
Jul 17 '05 #20
Hi Cedric,

I found something.

I ALWAYS get this error:
Inappropriate ioctl for device

I googled for it but didn't find a clear solution, allthough it can have to
do with redirects by the webserver with or without trailing slashes.

http://aspn.activestate.com/ASPN/Mai...php-Dev/763315

That article is from 2001, so I am unsure if it is still relevant.

I think you maybe better use the page without /temp and do some parsing.
The same data is there and that page works fine.

Anyway, here follows some (stinking) code that gets the info out:
I guess somebody who knows regexpressions better than I can code it more
elegant. :P

The 4 echo's at the end include the celcius still.
You could rip that too of course.

<?

$lines = file("http://195.68.51.202");

// it is all on one line, so:
$line = $lines[0];

// this is the essential part:
// <td>Probe 4</td></tr><tr><td>27.5 &deg;C</td><td>23.6
&deg;C</td><td>-99.9 &deg;C</td><td>-99.9 &deg;C</td></tr></tbody></table>

// we want this part:
// 27.5 &deg;C</td><td>23.6 &deg;C</td><td>-99.9 &deg;C</td><td>-99.9 &deg;C

$boundary1 = "Probe 4</td></tr><tr><td>";
$boundary2 = "</td></tr></tbody></table>";

$pos1 = strpos($line, $boundary1);
$pos2 = strpos($line,$boundary2 );
$temps = substr ( $line, $pos1+strlen($boundary1),
($pos2-$pos1-strlen($boundary2)+1));

$tempArr = explode ("</td><td>",$temps);

echo htmlentities($temps)."<br>";

echo $tempArr[0]."<br>";
echo $tempArr[1]."<br>";
echo $tempArr[2]."<br>";
echo $tempArr[3]."<br>";
?>
I am sorry I couldn't help you the right way (by getting the /temp working)
but this gets the job done. :-)

Regards,
Erwin Moller
Jul 17 '05 #21
Michael Fesser wrote:
.oO(VooDoo)
http://195.68.51.202
here you can find the sensor page


The main page works, but I can't access http://195.68.51.202/temp/ with
a lynx-browser. Web-sniffer also shows nothing:

<http://web-sniffer.net/?url=http%3A%2F%2F195.68.51.202%2Ftemp%2F>

No response ... strange. So I would rather parse the main page to get
the results, shouldn't be too difficult, something like

$data = file_get_contents('http://195.68.51.202/');
preg_match_all('#>([^>]+?) &deg#', $data, $matches);
print_r($matches[1]);

HTH
Micha


LOL!

Micha, I just posted a script of a lot more lines.
Do you also give classes? I want to come. :-)
Regards,
Erwin Moller
Jul 17 '05 #22
VooDoo wrote:
http://195.68.51.202
here you can find the sensor page
if that can you give more ideas...
thanks a lot again for helping me on this
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...


This worked for me. The code is from the docs for fsockopen:

$fp = fsockopen("195.68.51.202", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /temp/ HTTP/1.1\r\n";
$out .= "Host: 195.68.51.202\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

Using fopen worked OK for http://195.68.51.202/, but failed on
http://195.68.51.202/temp/. Also, tcpdump showed checksum errors when
connecting with fopen. Anyone experience the same (PHP 4.3.2 on OS X)?

Regards, Anders
VooDoo wrote:

reply below
"Erwin Moller"
<si******************************************@s pamyourself.com> a ?rit
dans le message de news:41***********************@news.xs4all.nl...

VooDoo wrote:
>same thing with thte new code..... :(
>"VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
>news:cf**********@reader1.imaginet.fr...
>
>>Thanks erwin.
>>No apparently the web server only send out this line:
>>Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>>nothing else, no html code at all.
>>If i use the default page of the server (192.168.10.220) where there
>>is

a

>>full of other caracter, then it works fine...
>>the constructo said that the page192.168.10.220/temp has been
designed
to

>>fit custom application, and it just provided the value of the
>>different probe...
>>i try out your new code and let you know...

Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:

>>No apparently the web server only send out this line:
>>Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";

}

produces nothing?

Yes !

And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES

Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";

}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue
for
them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10


first.
Do you get an answer?

Regards,
Erwin Moller





Jul 17 '05 #23
.oO(Erwin Moller)
Micha, I just posted a script of a lot more lines.
Do you also give classes? I want to come. :-)


*g*

Nope, sorry. ;D

Micha
Jul 17 '05 #24
I was interesting too!! ;)
Anyway thanks a lot to both of you, you have been very very helpfull on
that!!
Your last solutions worked fine, so i am parsing the main page... wich was
not designed for that but it's working fine so....
Just for your info here is the response of the constructor:
Bizarre,

Sounds like a problem with fopen()....might be because the /temp is like

a .cgi script....not a static index page like temp.html. Can you use

something like netcat (http://netcat.sourceforge.net/). What do you

think? There is another utility out there to retrieve URL's...wget I

beleive is the name of it...and it doesn't work with the /temp URL

neither. Could also be because the /temp URL doesn't return any HTML

encoding.

Looks like he does not know also the reason of that problem...

Another big thanks for you guys.

Thanks

Hope i will help you one day;)

Rdgs,

voodoO
"Michael Fesser" <ne*****@gmx.net> a écrit dans le message de
news:jb********************************@4ax.com...
.oO(Erwin Moller)
Micha, I just posted a script of a lot more lines.
Do you also give classes? I want to come. :-)


*g*

Nope, sorry. ;D

Micha

Jul 17 '05 #25
.oO(VooDoo)
I was interesting too!! ;)
Anyway thanks a lot to both of you, you have been very very helpfull on
that!!
Your last solutions worked fine, so i am parsing the main page... wich was
not designed for that but it's working fine so....
You can also use the solution posted by Anders Lövgren (connect with
fsockopen and manually send a GET request), this works with the /temp
file.
Just for your info here is the response of the constructor:
Bizarre,
Sounds like a problem with fopen()....might be because the /temp is like
a .cgi script....not a static index page like temp.html. Can you use
something like netcat (http://netcat.sourceforge.net/).
netcat works:

$ nc 195.68.51.202 80
GET /temp HTTP/1.1

returns the data.
What do you
think? There is another utility out there to retrieve URL's...wget I
beleive is the name of it...and it doesn't work with the /temp URL
neither.
wget fails:

$ wget -t1 http://195.68.51.202/temp
--16:01:15-- http://195.68.51.202/temp
=> `temp'
Connecting to 195.68.51.202:80... connected.
HTTP request sent, awaiting response...
End of file while parsing headers.
Giving up.
lynx also fails:

$ lynx -head http://195.68.51.202/temp
Looking up 195.68.51.202
Making HTTP connection to 195.68.51.202
Sending HTTP request.
HTTP request sent; waiting for response.
Alert!: Unexpected network read error; connection aborted.
Can't Access `http://195.68.51.202/temp'
Alert!: Unable to access document.
Could also be because the /temp URL doesn't return any HTML
encoding.


I think there's a little problem with the built-in webserver, looks like
some specific request headers causes it to fail (simple requests work),
but I haven't investigated any further.

Micha
Jul 17 '05 #26
<snip>
You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Sniffing with IE6 and a nice little gem called HTTPWatch reveals that
this is *all* that is sent.
Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
Not apparently in all web browsers. IE6 and Firefox show content --
Lynx does not.

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.


The fact is that NO HTTP headers are being sent as part of the
response. As such, PHP's fopen URL wrappers parse the response, but
do not find valid "content" since no headers exist to describe the
delivered payload.

Hope this is understandable and clears it up why PHP showed nothing
using the fopen functions.
heyster
Jul 17 '05 #27
heyster wrote:
<snip>
You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Sniffing with IE6 and a nice little gem called HTTPWatch reveals that
this is *all* that is sent.
Question: How do you know this?
That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .
"<br>\n";
}

produces nothing?
Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
Not apparently in all web browsers. IE6 and Firefox show content --
Lynx does not.

???

Is that true?
YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.


The fact is that NO HTTP headers are being sent as part of the
response. As such, PHP's fopen URL wrappers parse the response, but
do not find valid "content" since no headers exist to describe the
delivered payload.

Hope this is understandable and clears it up why PHP showed nothing
using the fopen functions.
heyster


Hi heyster,

I found out the same results. No headers, just a line.
Question:
Could we use a straight socketconnection on that x.x.x.x/temp to get the
line in?

Regards,
Erwin Moller
Jul 17 '05 #28
On Mon, 23 Aug 2004 11:30:29 +0200, Erwin Moller
<si******************************************@spam yourself.com> wrote:

Hi heyster,

I found out the same results. No headers, just a line.
Question:
Could we use a straight socketconnection on that x.x.x.x/temp to get the
line in?

Regards,
Erwin Moller


Erwin,

Yes, and it looks like that's what worked for Anders Lövgren based on
his post of a few days ago.

Too bad the device doesn't use valid headers when addressed at
"/temp", but good to know the nut wasn't too tough to crack.

heyster
Jul 17 '05 #29
Check out iewatch.com for a great tool to debug HTTP...
heyster <he***********@eysterengineered.com> wrote in message news:<vh********************************@4ax.com>. ..
<snip>
You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Sniffing with IE6 and a nice little gem called HTTPWatch reveals that
this is *all* that is sent.
Question: How do you know this?
That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; }

produces nothing? Yes ! And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
Not apparently in all web browsers. IE6 and Firefox show content --
Lynx does not.

???

Is that true? YES Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.


The fact is that NO HTTP headers are being sent as part of the
response. As such, PHP's fopen URL wrappers parse the response, but
do not find valid "content" since no headers exist to describe the
delivered payload.

Hope this is understandable and clears it up why PHP showed nothing
using the fopen functions.
heyster

Jul 17 '05 #30

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Xah Lee | last post: by
1 post views Thread by fabrice | last post: by
19 posts views Thread by Lionel B | last post: by
4 posts views Thread by Oliver Knoll | last post: by
6 posts views Thread by Rajorshi Biswas | last post: by
7 posts views Thread by John Dann | last post: by
6 posts views Thread by efrenba | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.