无法阻止 PHP 字符串文字的格式化
我的 php 中有一行这样的代码:
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item->getItemName()));
当我在其上运行 Aptana PHP 格式化程序时,我得到:
$val = preg_replace('/<\/?div.*
?>/
', '', str_replace("
<br />
", " - ", $item->getItemName()));
我创建了一个自定义格式化程序并启用了开/关标签,并像这样设置了我的代码:
//@formatter:off
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item->getItemName()));
//@formatter:on
但它仍然格式化它。显然这是 HTML 格式化程序被触发,所以我什至尝试将其关闭,以防万一这是问题所在:
//<!--@formatter:off-->
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item->getItemName()));
//<!--@formatter:on-->
仍然没有运气。对我做错了什么有什么想法吗?
I have a line of code like this in my php:
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item->getItemName()));
When I run the Aptana PHP formatter on it I get:
$val = preg_replace('/<\/?div.*
?>/
', '', str_replace("
<br />
", " - ", $item->getItemName()));
I created a custom formatter and enabled on/off tags and setup my code like so:
//@formatter:off
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item->getItemName()));
//@formatter:on
But it still formats it. Obviously it's the HTML formatter getting triggered, so I even tried turning that off just in the off chance it was the problem:
//<!--@formatter:off-->
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item->getItemName()));
//<!--@formatter:on-->
Still no luck. Any thoughts on what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试重新创建这个,但没有真正成功。
当我有这段代码时,格式化程序工作得很好:
删除开始
标签和结束
?>
,实际上会调用 HTML 格式化程序代码,因为它将被视为 PHP 文件中的 HTML。如果您在此处发布完整的文件,将更容易看出错误在哪里,或者格式化程序是否存在问题。
希望有帮助。
I tried to recreate this one, but with no real success.
When I have this code, the formatter works just fine:
Removing the opening
<?php
tag, and the closing?>
, will actually invoke the HTML formatter on the code, as it will be treated as HTML in a PHP file.If you post the complete file here, it will be easier to see where is the mistake, or if there is an issue with the formatter somewhere.
Hope that helps.