更改输出的颜色。 PHP [英] Change color of output. PHP

查看:167
本文介绍了更改输出的颜色。 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个从cisco router / switch返回接口状态的脚本。
现在,我想根据字词更改文字的颜色。



例如:


  1. connected = green

  2. notconnected = red

可能?

  $ host =主机名; 
$ name =my.username\r;
$ pass =mypassword\r;

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

echo'< img src =\img\banner.jpgstyle =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:我可以在哪里发布脚本?我打赌有很多网络工程师对此感兴趣。

解决方案

这可以用简单的内联css:

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

但你应该使用类并在嵌入的样式表中声明样式。


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.

解决方案

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.

这篇关于更改输出的颜色。 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆