使用 preg_replace 从字符串中间突出显示子字符串
Highlight a sub string from middle of the string with preg_replace
我想将数字字符串的中间部分加粗。
我有一个数字字符串:
$nmbr="55113741659856";
我想突出显示中间的4个数字,从第6位开始
......7416......
并用粗体字母替换它们
<b>7416</b>
我当前的代码无法执行我想要的操作
$nmbr="55113741659856";
preg_replace("/d+([0-9]{4,6})/i","<b></b>",$nmbr);
非常感谢您的帮助。
谢谢。
您忘记添加 \d+
。
preg_replace("/\d+([0-9]{4,6})/i","<b></b>",$nmbr);
原因是:
\d Find a digit
你错过了这里的 \
。
I want to highlight 4 numbers in the middle ,from the 6th position
我愿意:
$nmbr="55113741659856";
preg_replace("/^(\d{5})(\d{4})/","<b></b>",$nmbr);
我想将数字字符串的中间部分加粗。
我有一个数字字符串:
$nmbr="55113741659856";
我想突出显示中间的4个数字,从第6位开始
......7416......
并用粗体字母替换它们
<b>7416</b>
我当前的代码无法执行我想要的操作
$nmbr="55113741659856";
preg_replace("/d+([0-9]{4,6})/i","<b></b>",$nmbr);
非常感谢您的帮助。
谢谢。
您忘记添加 \d+
。
preg_replace("/\d+([0-9]{4,6})/i","<b></b>",$nmbr);
原因是:
\d Find a digit
你错过了这里的 \
。
I want to highlight 4 numbers in the middle ,from the 6th position
我愿意:
$nmbr="55113741659856";
preg_replace("/^(\d{5})(\d{4})/","<b></b>",$nmbr);