gpt4 book ai didi

javascript - 自动为表单中的数字添加粗体

转载 作者:太空宇宙 更新时间:2023-11-04 02:55:41 25 4
gpt4 key购买 nike

所以我想要一个脚本,在发送表单后它会添加 到输入表单中添加的数字。

例如

Ability power ratio increased to <b>0.8</b> from <b>0.5</b>.
<b>20%</b> and <b>40/50/60/80</b>

我真的不知道这样的脚本背后的逻辑。如果它是数字或字符,我可能会使用 substr() 并首先逐个字母地检查。很抱歉这个问题太直率了,但我不知道如何解决这个问题。

<form name="second_form" id="second_form" action="#" method="POST">         
<div class="Change">
<textarea type="text" size="20" rows="3" cols="50" maxlength="500" name="SpellDescription[]" placeholder="Enter Description" required>
</textarea>
</div>
<br><br>
<input type="submit" name="submit">
</form>

最佳答案

尝试 preg_replace

echo preg_replace( '/([0-9]+)\.?(\/?[0-9\.?]*)*%?/', '<strong>$0</strong>', 'test 0.1 this 5 test 0/1/2/3 5% 50% 5.5% 5   % . / 5/5.5/3/1.5/35.5/1.75');

您也可以在这里自己尝试一下:PHP Fiddle为了完善正则表达式(因为你可以用它做很多事情),请在 regexr 上摆弄。

按照 caCtus 的建议编辑了正则表达式,感谢您的输入!

关于javascript - 自动为表单中的数字添加粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32229012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com