PHP正则表达式生成HTML
我有以下问题。我想创建一个preg_replace()函数来替换,例如: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
[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>