请原谅我对我想要学习的内容的错误描述。 我是编码网站的新手。
我正在尝试为变量的结果着色。 如果该值大于零,则颜色应为红色。
我的代码如下:
$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/