我正在处理这个我在preg_replace中使用的正则表达式,在divs
周围添加/divs
和*
。它现在使用两个*
。只用一个*
当前
<?php
$errors = 1;
$arr['ERR'] = '';
$arr['ERR'] .= '*<i>Error 1</i>*';
$arr['ERR'] .= '*<i>Error 2</i>*';
$arr['ERR'] .= '*<i>Error 3</i>*';
$arr['ERR'] .= '*<i>Error 4</i>*';
$arr['ERR'] .= '*<i>Error 5</i>*';
$arr['TOF'] = 'Success';
$arr = preg_replace('#\*(.+?)\*#', '<div>$1</div>', $arr);
print_r( $arr );
// output
array (
[ERR] => <div><i>Error 1</i></div><div><i>Error 2</i></div><div><i>Error 3</i></div><div><i>Error 4</i></div><div><i>Error 5</i></div>
[TOF] => Success
)
?>
尝试
$arr['ERR'] = '';
$arr['ERR'] .= '*<i>Error 1</i>';
$arr['ERR'] .= '*<i>Error 2</i>';
$arr['ERR'] .= '*<i>Error 3</i>';
$arr['ERR'] .= '*<i>Error 4</i>';
$arr['ERR'] .= '*<i>Error 5</i>';
$arr['TOF'] = 'Success';
$arr = preg_replace('#\*(.+?)#', '<div>$1</div>', $arr);
//just one * but get the same results as above.
如何使用正则表达式只使用一个*