Change color of output. PHP

我只是一个虾纸丫 提交于 2020-01-07 03:03:58

问题


I created an script that returns interface status from cisco router/switch. Now, i want to change the color of my text based on the word

Ex:

  1. connected=green
  2. notconnected=red

Is this possible ?

part of my script:

 $host = "hostname";
    $name = "my.username\r";
    $pass = "mypassword\r";

    $form = <<<END
    <form method='post' action='' style='margin:auto; width:400px'>
          Adresa IP host : <input type='text' name='host'><br><br>
          <input type='submit' name='submit' value='Connect'>
    </form>
    END;

    echo '<img src="\img\banner.jpg" style="margin:auto; display:block"/><br>';


    echo $form;

    $t = new TELNET();
    if (!empty($_POST)){
       $host = $_POST['host'];
       echo("CONNECT:".$t->Connect($host, $name, $pass)."<br>");
       echo("LOGIN:".(int)$t->LogIn());
       echo("<br>Status Interfete:<br>");
      $interfaces_status = ($t->GetOutputOf("show interface status"));
    foreach ($interfaces_status as $value) {
        echo "$value <br>";

PS: where can i post the script ? I bet there are alot of network engineers interested in this.


回答1:


That's possible with simple inline css:

<?php foreach ($interfaces_status as $value) { ?>
        <span style="color:<?php echo ($value == 'connected') ? 'green' : 'red'; ?>"><?php echo $value; ?><br />
<?php } ?>

But you should rather use classes and declare the styles in an embeded stylesheet.



来源:https://stackoverflow.com/questions/33737090/change-color-of-output-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!