Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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
PHP正则表达式生成HTML_Php_Regex - Fatal编程技术网

PHP正则表达式生成HTML

PHP正则表达式生成HTML,php,regex,Php,Regex,我有以下问题。我想创建一个preg_replace()函数来替换,例如: [div_row_392]...text...[/div] 到 …文本。。。 这可能适合您: $html = "[div_row_392]...text...[/div]"; $html = preg_replace('%\[(.*?)_(.*?)_(.*?)\](.*?)\[/(.*?)\]%sim', '<$1 class="$2" id="$3">$4</$5>', $html); echo

我有以下问题。我想创建一个preg_replace()函数来替换,例如:

[div_row_392]...text...[/div]

…文本。。。
这可能适合您:

$html = "[div_row_392]...text...[/div]";
$html = preg_replace('%\[(.*?)_(.*?)_(.*?)\](.*?)\[/(.*?)\]%sim', '<$1 class="$2" id="$3">$4</$5>', $html);
echo $html;
//<div class="row" id="392">...text...</div>
$html=“[div_row_392]…text…[/div]”;
$html=preg\u replace('%\[(.*?)\(.*?)\.[/(.*?\]]%sim','$4',$html);
echo$html;
//…文本。。。

这是一个方便的测试网站,这是一个方便的工具,谢谢!你是说这个?
$html = "[div_row_392]...text...[/div]";
$html = preg_replace('%\[(.*?)_(.*?)_(.*?)\](.*?)\[/(.*?)\]%sim', '<$1 class="$2" id="$3">$4</$5>', $html);
echo $html;
//<div class="row" id="392">...text...</div>