开发者

cant get regex to work as i want

开发者 https://www.devze.com 2022-12-26 03:58 出处:网络
With this function: function bbcode_parse($str) { $str = htmlentities($str); $find = array( \'/\\\\*\\*(.[^*]*)\\*\\*/is\',

With this function:

function bbcode_parse($str) {
$str = htmlentities($str);

$find = array(  
    '/\\*\*(.[^*]*)\*\*/is',
);

$replace = array(
    '<b>' 
);

$str = preg_replace($find, $replace, $str);  

return $str;
}

And with text "My name is **bob**"

I get in source code Hi my name is <b>

Been trying to get this to work for a while now.

Would ap开发者_如何转开发pricate some expert help :)


(In bbcode you bold text with [b]xxx[/b] not **xxx**.)

In PHP, you can use $1 to represent the captured subgroup, so your replacement should be

'<b>$1</b>'


Try using this:

preg_replace("/.*\*{2}(.+?)\*{2}.*/", "<b>$1</b>", "My name is **bob**");
0

精彩评论

暂无评论...
验证码 换一张
取 消