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

标签 javascript php html css

请原谅我对我想要学习的内容的错误描述。 我是编码网站的新手。

我正在尝试为变量的结果着色。 如果该值大于零,则颜色应为红色。

我的代码如下:

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

结果是这样的:

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 |

是否可以为大于零的数字着色? 有什么想法吗?

最佳答案

例如,您可以在您的内容上应用 preg_replace 来检查数字并将其环绕!

$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;

(尚未测试但可能有效)

关于javascript - 如何在 file_get_contents 和 echo $content 之后为数字着色;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51843748/

相关文章:

javascript - 快速单元测试,在服务器上调用 close 结果为 `call of undefined`

javascript - 使用 jquery.scrollTo 时使用 jQuery 处理元素 ID 中的冒号

javascript - HTML 基本弹球游戏

javascript - React TypeError : _this2. props.variations.find 不是函数

javascript - 在 jQuery 中获取当前元素的类

javascript - 当数据不在范围内时如何使用正则表达式返回 false?

html - 强制水平表格滚动条

php - 如何在数据库中插入带有双引号的值?

php - pecl install intl 没有可用的版本?

php - 使用 log4php 跟踪 php 上的用户事件