Regex 预更换、BBCODE和新行
我正在使用替换方法来生成[product]ID | text[/product],在我尝试在文本部分生成一行新行之前,它的效果非常好。然后它就坏了,根本不更换 功能: 函数productBox($matches){Regex 预更换、BBCODE和新行,regex,preg-replace,preg-replace-callback,Regex,Preg Replace,Preg Replace Callback,我正在使用替换方法来生成[product]ID | text[/product],在我尝试在文本部分生成一行新行之前,它的效果非常好。然后它就坏了,根本不更换 功能: 函数productBox($matches){ 有谁能在这里帮我解决如何在文本部分使用新行的问题吗?更可爱的是重新制作它,使其像这样工作,而且可能更容易?:[product id=“id”]文本和更多文本[/product]只需添加多行修饰符: $pattern = "/\[product\](.+?)\[\/product\]/
有谁能在这里帮我解决如何在文本部分使用新行的问题吗?更可爱的是重新制作它,使其像这样工作,而且可能更容易?:[product id=“id”]文本和更多文本[/product]只需添加多行修饰符:
$pattern = "/\[product\](.+?)\[\/product\]/s";
// here __^
$content = get_the_content();
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$pattern = "/\[product\](.+?)\[\/product\]/";
$content = preg_replace_callback($pattern, 'productBox', $content);
$pattern = "/\[product\](.+?)\[\/product\]/s";
// here __^