【发布时间】:2013-12-18 09:07:30
【问题描述】:
我在从模板文件的标记中删除换行符时遇到了另一个问题 - 我必须解析的模板可能如下所示:
<html>
<style>
body { color: black }
div {
background-color:#fff;
}
<!-- i need to remove the line breaks within {_WP_token[*]} for parsing //-->
<h4>{_WP_token[id="42";class="foo"; style="border:4px solid
green;padding:20px"; onclick="(this.value=confirm('foo'));"]}</h4>
<script>
function() {
console.log('my foo is my castle');
}
</script>
我尝试了自己但没有取得突破。我刚刚成功地创建了一个贪婪的,它吃掉了令牌的前半部分 - 这里是:
preg_replace("/(\{_(.*?)(.*\s))/ix", "[LB REMOVED]", $htmlTemplate);
返回
<html>
<style>
body { color: black }
div {
background-color:#fff;
}
<!-- it just ate up the first half of my token ! //-->
<h4>[LB_REMOVED]green;padding:20px"; onclick="(this.value=confirm('foo'));"]}</h4>
<script>
function() {
console.log('my foo is my castle');
}
</script>
我在这里做了一个小提琴:http://www.phpliveregex.com/p/2EZ
非常感谢您。
最好的问候, 卢波
【问题讨论】:
标签: php regex line-breaks