php - 查找单词并更改颜色

标签 php html css

我想使用 CSS 和条件更改在 ECHO 函数中找到的文本的颜色。

例如:

我使用 ECHO 函数调用文本:

echo ": The net value of the entire order"
echo ": The gross value of the entire order"
echo ": The gross value of the entire order"
echo ": The net value of the entire order"

然后使用条件“if”找到单词“net”或“gross”并将颜色更改为红色或蓝色..

怎么做?我正在寻找论坛,但帖子仅针对变量中的赋值,我想从 ECHO 函数更改颜色,这似乎毫无意义,但如果有成千上万这样的话?

我向你求助, 我是这门语言的新手。

最佳答案

$str = ": The net value of the entire order"

$str = str_replace('net', '<span style="color:red">net</span>', $str);
$str = str_replace('gross', '<span style="color:blue">gross</span>', $str);

echo $str;

关于php - 查找单词并更改颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52401887/

相关文章:

php - 使用 $_GET 传递成员(member) ID

php - 如何 "un-slug"标题 slug

html - 我可以在样式表中覆盖元素的内联样式吗?

javascript - 通过循环动态显示html元素

css - 如何更改与事件页面对应的超链接中的图像?

html - 从 DIV 隐藏滚动条

php - Apache 持续利用更多内存

javascript - md5 字符串的 base64_encoding - php 与 javascript 问题

html - 将文字置于绝对图像之上

html - css3 仅选项卡预选选项卡