/    Sign up×
Community /Pin to ProfileBookmark

Post image if line exist

I’m trying to create a simple webpage that post certain images after it has checked the webpage [url]http://10.10.1.5/text.html[/url] for either the line

var txAudioRate=’—‘;

or

var txAudioRate=’64k’;

or

if the page is unreachable or doesn’t exist to post the last image:

The line var txAudioRate exist on line 30 of the test.html, and I do not have access to change the file test.html. I’ve created my own page mypage.php so here is what I’ve come up with so far:

<?php
$farray = file(“http://10.10.1.5/test.html“);

if(strpos($farray[30],”txAudioRate=’64k’;”)) {
echo “<img src=images”example1.jpg” alt=””>”;
}
else if(strpos($farray[30],”txAudioRate=’—‘;”)) {
echo “<img src=images”example2.jpg” alt=””>”;
}
else {
echo “<img src=images”example3.jpg” alt=””>”;
}
?>

Here is the problem I’ve run into so far. Even if the line txAudioRate=’64k’ or txAudioRate=’—‘ it always post example3.jpg.

Another problem is that if it can’t find the file, it post this long message Warning: file(text.html) [function.file]: failed to open stream: No such file or directory in c:Inetpubwwwrootmypage.php on line 12 instead of just posting the example3.jpg by itself. Any Ideas?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@artemisSep 14.2004 — [font=technical][size=3]this should fix your problems

[font=monospace][size=5]
[code=php]
<?php
$farray = file("http://10.10.1.5/test.html");

if(strpos($farray[30],"txAudioRate='64k';")!==false) {
echo "<img src=images"example1.jpg" alt="">";
}
else if(strpos($farray[30],"txAudioRate='---';")!==false) {
echo "<img src=images"example2.jpg" alt="">";
}
else {
echo "<img src=images"example3.jpg" alt="">";
}
?>
[/code]
[/size][/font]

the [i]!==false[/i] bit checks that the string is definitly somewhere in the string. if this was not there and the string was at the beginning of the main string then a null would be returned and it would move on.[/size][/font]
Copy linkTweet thisAlerts:
@cloudyimpulseauthorSep 14.2004 — That still doesn't seem to be working... Same issue seems to happen. Gonna triple check but I don't know what's going on.
Copy linkTweet thisAlerts:
@Paul_JrSep 15.2004 — [i]Originally posted by cloudyimpulse [/i]

[B]Here is the problem I've run into so far. Even if the line txAudioRate='64k' or txAudioRate='---' it always post example3.jpg.[/b][/quote]

Are you sure the text is on that specific line? Also, remember that array indices start at 0, so the script is actually checking line 31 (if you start counting the lines at 1).

[i]Originally posted by cloudyimpulse [/i]

[B]Another problem is that if it can't find the file, it post this long message Warning: file(text.html) [function.file]: failed to open stream: No such file or directory in c:Inetpubwwwrootmypage.php on line 12 instead of just posting the example3.jpg by itself. Any Ideas? [/B][/QUOTE]

You can use the error control operator (the @ sign) to surpress errors by prepending the operator to the function call, like so:
[code=php]
<?php
$farray = @file("http://10.10.1.5/test.html");
# Rest of code
?>
[/code]
Copy linkTweet thisAlerts:
@cloudyimpulseauthorSep 15.2004 — Ok that def. seemed to work. I have another new problem now. I'm doing this check on multiple units that I've put in a table. Example:

<tr>

<td><b>Chicago Culture Center</b></td>

<td width="50"><?php

$ccc1 = @file("http://172.18.188.122/a_advannetstat.htm");

if(strpos($ccc1[25],"txAudioRate='64k';")!==false) {

echo "<img src="imagesconnected.gif" alt="The Unit is Currently in a Call">";

}

else if(strpos($ccc1[25],"txAudioRate='---';")!==false) {

echo "<img src="imagesonline.jpg" alt="The Unit is Currently Online">";

}

else {

echo "<img src="imagesoffline.gif" alt="The Unit is Currently Offline">";

}

?></td>

</tr>

<tr>

<td><b>Dallas Culture Center</b></td>

<td width="50"><?php

$dcc1 = @file("http://172.18.192.34/a_advannetstat.htm");

if(strpos($dcc1[25],"txAudioRate='64k';")!==false) {

echo "<img src="imagesconnected.gif" alt="The Unit is Currently in a Call">";

}

else if(strpos($dcc1[25],"txAudioRate='---';")!==false) {

echo "<img src="imagesonline.jpg" alt="The Unit is Currently Online">";

}

else {

echo "<img src="imagesoffline.gif" alt="The Unit is Currently Offline">";

}

?></td>

</tr>


The Problem is there is like 23 units to check on my internal network so the code becomes very long. Also what happens is that it only seems to check and display the results for only 8 sites instead of all 23. I'm not sure why it stops and it is totally random where it decides to stop checking. I've refreshed and sometimes it will only display 4 sites, sometimes 2 sites, somtimes 10 sites. So is there anyway to shorten down this code like a ton? I'm not sure what I can eliminate or what...
×

Success!

Help @cloudyimpulse spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...