Jump to content

Recommended Posts

Well I've been incredibly needy lately - I appreciate the help this community has provided, its been great - you've been great.

 

Still dissecting the same code Im working on - now Ive realized I may have a need for a couple different issues that have developed..

 

The code:

$file = file("networkmap.asp");

// Strip HTML formatting
foreach(file('networkmap.asp.htm') as $cleared) {
list($router,$metric,$ping,$status)=explode(",",$strip_content);
echo $router;
echo $metric;
echo $ping;
echo $status;
if($status=='UP') {
echo '<img src="green.png" alt="up" />';
} else {
echo '<img src="red.png" alt="down" />';
}

echo '<hr />';
}
?>

 

Can I set it to recognize that if there is four items to explode - list $router, $metric, $ping, $status

But if only three - list $router, $metric, $status  (where if $status=DOWN than ping results are null.)

 

-- And to note, I am working with a file that I have no access to modify, is ASP, and am trying to work with to develop a better alternative, using existing resources.

 

I do have other questions, but I am trying to figure some out myself... may add to as I begin giving up...

 

Thanks for your continued help, its been wonderful.

Link to comment
https://forums.phpfreaks.com/topic/198581-explode-and-various-help/
Share on other sites

Why specify $file and then not using it and using file again? That's just a performance waste.

 

The way I would do it is to store the result from explode into a variable and the go from there. Also, what's $strip_content? It's undefined.

 

Snippet:

$parts = explode(',', $cleared);
if (count($parts) == 4 || $parts[3] == 'UP') {
     // server is up
} else {
     // server is down
}

I know I gave you this code a couple of days ago, when I was running on nothing but a couple monster drinks, and 1 hour sleep.  But:

 

foreach(file('networkmap.asp.htm') as $cleared) {

 

Should have been

foreach($file as $cleared) {

 

And your strip_content was from the strip_tags function.

 

 

After saying all of that, if $ping is null, it should still be listed as an empty value using explode.  Since, the comma(,) should still be there.  So if $status is equal to 'DOWN' then $ping should be empty().

You're right, I removed some code as Im running the working code from work on a local PC that I cannot gain access to without working on it locally... and I used some code that I worked on last night that has proven irrelevant as Ive tested... you can ignore some of the obvious errors in the provided code... sorry for the confusion.

 

I'll try that and report back.

 

One thing I was trying to do was remove the first line of code that read Last 'Updated {time/date}' right at the front of the listed items... or Id like to fetch that as well, im just not sure how to grab it and then tell the code to move on to the next line to actually start gathering the real data I need.  And as I worked (noting the undefined variables) I subtracted the first several characters to remove the time stamp completely... which ended up subtracting those first characters from each $value on every line...

 

@jcbones

 

Yes and you've been a huge help - as I mentioned the some of the code hasnt really panned out exactly the way i hoped - it just got more complicated the more I tried.  strip_tags worked... but it stripped <script></script> and left the JS between -- creating a bunch of problems when the code tried to create the exploded values.. havnt figured that part out yet either (and 'course I left parts of that code unintentionally for this question)

 

And - CORRECTION - its not a null value where $router, $metric, , $status ... the $ping value simply is being skipped entirely by the ASP (that I cannot change) instead its $router, $metric, $status  ONLY when $status = DOWN

 

my last dilemma will be either getting some change to that ASP or figuring out a way to have PHP do it for me -- where each item should be a new line is actually a REALLLY long line of ALL items.... so right now Ive got the first 4 items exploded and nothing beyond that.  Im hoping I can get authorization to modify the ASP to create a new line before outputting the HTML onto this text based network map.

 

This all could have been alot easier if I could get my hands on the resources im using, but working with what Ive got has made some headaches.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.