如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本

How to create a function in php which works with a textarea to print the text with the equivalent color by entering something like [color:red]

本文关键字:文本 函数 颜色 red color 打印 输入 创建 php 一起 工作      更新时间:2023-09-26

如何在PHP中创建一个函数,该函数与textarea一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本??

这个功能实际上和facebook的@[profile_id:0]类似。

如果你想要这个客户端:使用JS并解析文本区域的内容以找到类似[color:red]的BB代码,然后应用类似的东西

document.getElementById("yourTextArea").style.color = "red";

如果你想让它在服务器端让用户输入BB代码,点击提交按钮,文本就会以选定的颜色突出显示,那么你需要编写一个php函数来解析文本区域的内容。在此处使用preg_match()查找BB代码。