Replace certain part of a php string -
i have text (in specific case $expression
), quite long. want output text same way is, except outputting numbers %
bold. spelled 3%
, there's space 123 %
.
<?php $expression = 'here got number 23 % , on'; $tokens = "([0-9]+)[:space:]([\%])"; $pattern = '/[0-9][0-9] %/'; $keyword = array($pattern); $replacement = array("<b>$keyword</b>"); echo preg_replace($keyword, $replacement, $expression); ?>
this have i'm not sure i'm doing wrong. outputs error on line $replacement = array("<b>$keyword</b>");
, outputs actual string except replaces number%
<b>array</b>
.
try
$expression = 'here got number 23 % , on'; var_dump(preg_replace('/(\d+\s*\%)/', "<b>$1</b>", $expression));
Comments
Post a Comment