Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 预更换、BBCODE和新行_Regex_Preg Replace_Preg Replace Callback - Fatal编程技术网

Regex 预更换、BBCODE和新行

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 | text[/product],在我尝试在文本部分生成一行新行之前,它的效果非常好。然后它就坏了,根本不更换

功能: 函数productBox($matches){


有谁能在这里帮我解决如何在文本部分使用新行的问题吗?更可爱的是重新制作它,使其像这样工作,而且可能更容易?:[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 __^