Getting HTML from URL.

Hello, I’m need to get content from a URL however 2 conditions have to be met before the content is echod on the page. I am using file_get_contents and strpos which works good with 1 condition however I don’t know how to get 2 to work. So basically I need to check the URL…if 2 of the set conditions/parameters/search variables are met…then echo the HTML data

Thanks for any help, Dave

something like this?
[php]
if ((isset($_GET[‘cmd’])) && (isset($_GET[‘ID’])))
{

if ($_GET['cmd'] == "view")
{
echo "view";
}elseif	($_GET['cmd'] == "update")
{
echo "update";
}elseif	($_GET['cmd'] == "delete")
{
    echo "delete";
}

}
[/php]

Thanks Wilson , I’ll try that in the morning. I’m trying to get weather warning text from a URL…and the conditions would be TORNADO WARNING FOR: … And then the city…if there is those 2 things in the HTML…then show all of it on my page.

cool, make sure you make the necessary changes

good luck

Quick question. Where would I add in the URL to be read?

well i dont know i would need to know what you really really want to do or by showing us some codes

I’ll report back in the morning with what I had and what I need, have a good night!

OK, Here is the link http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html . If that link has the text TORNADO WARNING FOR: as well as WINDSOR - LEAMINGTON - ESSEX COUNTY …echo the text on my page…

What I have done so far works with 1 condition/parameter but not 2. Any help would be great.
[php]<?php

$tester = file_get_contents(‘http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html’); //$tester contains contents to search
$tornado = ‘TORNADO WARNING ENDED FOR:’;
$city = ‘SMITHS FALLS - LANARK - SHARBOT LAKE’;

if(preg_match( “/$tornado|$city/i”, $tester ) ){

echo '<img style=“position:absolute;left:50%;margin-left:-397px; margin-top:30px” src="/Warningoverlays/TOR

Warn/windsor.png" border=“0”>’;

}
else
{
echo ‘’;
}
?>[/php]

try it this way:

[php]

<?php $tester = file_get_contents('http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html'); //$tester contains contents to search $tornado = 'TORNADO WARNING ENDED FOR:'; $city = 'SMITHS FALLS - LANARK - SHARBOT LAKE'; if ((strpos($tester, $tornado)) && (strpos($tester, $city))) { echo ''; } else { echo ''; } ?>

[/php]

so if both sentences ‘TORNADO WARNING ENDED FOR:’ and ‘SMITHS FALLS - LANARK - SHARBOT LAKE’ are matched it will print the image. it is case sensitive

et me know if it works

Works wonderful, thanks very much. I will just change the image now to echo the html. 1 quick question though…is it possible to echo just the text and not the image and link on that html page?
Thanks for all the help!

Dave,

Sure, you can echo texts and HTML tags

[php]
echo “

Hello

”; //this a HTMl header 1
echo “Hello world”; // this is just text
[/php]

OK, I have it echoing the whole html link with the text…and it shows the images and background as well
seen here http://www.southernontariochasing.ca/test.php is it possible to have just the text and not the background and other images?

yeah sure, show me the codes i will do it

I need to have the text between the 2

 html tags [php]
 &nbsp
037 &nbsp
WFCN11 CWTO 231941 &nbsp
TORNADO WARNING &nbsp
ENDED BY ENVIRONMENT CANADA &nbsp
AT 3:41 PM EDT MONDAY 23 JULY 2012. &nbsp
--------------------------------------------------------------------- &nbsp
TORNADO WARNING ENDED FOR: &nbsp
SMITHS FALLS - LANARK - SHARBOT LAKE &nbsp
BARRY’S BAY - KILLALOE &nbsp
RENFREW - ARNPRIOR - CALABOGIE. &nbsp
&nbsp
--------------------------------------------------------------------- &nbsp
==DISCUSSION== &nbsp
THE TORNADO THREAT HAS DIMINISHED. &nbsp
&nbsp
END/OSPC &nbsp
 
[/php]

sorry, i do not know what you want to do.

When the 2 conditions are met…instead of echoing the whole html file…i just need to echo the text
I have it working good here for the whole html file…however I only need the text thats between those 2 tags I listed above.
[php]<?php
$tester = file_get_contents(‘http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html’); //$tester contains contents to search
$tornado = ‘TORNADO WARNING ENDED FOR:’;
$city = ‘SMITHS FALLS - LANARK - SHARBOT LAKE’;

if ((strpos($tester, $tornado)) && (strpos($tester, $city)))
{
echo $tester;
}
else
{
echo ‘’;
}
?>[/php]

you want to echo $tornado and $city?

that will look like this on the browser?

TORNADO WARNING ENDED FOR: SMITHS FALLS - LANARK - SHARBOT LAKE

I want to echo the text from the first number…in this case 037 all the way to END/OSPC. between the 2

 tags in the source.

you want to echo ?

037
WFCN11 CWTO 231941
TORNADO WARNING
ENDED BY ENVIRONMENT CANADA
AT 3:41 PM EDT MONDAY 23 JULY 2012.

TORNADO WARNING ENDED FOR:
SMITHS FALLS - LANARK - SHARBOT LAKE
BARRY’S BAY - KILLALOE
RENFREW - ARNPRIOR - CALABOGIE.


==DISCUSSION==
THE TORNADO THREAT HAS DIMINISHED.

END/OSPC

Yes, correct.

Sponsor our Newsletter | Privacy Policy | Terms of Service