dousong3760 2018-08-14 14:24
浏览 82

如何在file_get_contents和echo $ content之后为数字着色;

Excuse me for my bad description of what I am looking to learn. I am new on coding sites.

I am trying to colorize the results of a variable. If the value is bigger than zero then color should be red.

My code is the following:

$content="
    <h2>---3 HH and 3 LL FIBO--- </h2>
        <code>
            <pre>".htmlspecialchars(file_get_contents("$path/$file"))."</pre>
        </code>";
echo $content;

And the result is something like this:

Balance | Equity | Used Mr | Usable Mr, % |

38.610,21 | 65.781,67 | 19.900,00 | 69,75 | 

Symbol |Amount|S/B| P/L | Gross P/L | 

EUR/CAD | 500 | S | 201,2 | 7.687,34 |

Is it possible to color the numbers if they are bigger than zero? Any ideas?

  • 写回答

1条回答 默认 最新

  • doupiao9318 2018-08-14 14:47
    关注

    You can appy a preg_replace on your content to check for numbers and wrap it around for exemple!

    $regex = '/((?!0)\d+((\.|\,)\d+)*)/';    
    $content="
        <h2>---3 HH and 3 LL FIBO--- </h2>
            <code>
                <pre>".preg_replace($regex, '<span class="color-red">$1</span>', htmlspecialchars(file_get_contents("$path/$file")))."</pre>
            </code>";
    echo $content;
    

    (Haven't tested but might work)

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP