无法阻止 PHP 字符串文字的格式化

发布于 2024-12-24 18:24:05 字数 838 浏览 5 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁虫ゝ 2024-12-31 18:24:05

我尝试重新创建这个,但没有真正成功。

当我有这段代码时,格式化程序工作得很好:

<?php
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item -> getItemName()));
?>

删除开始 标签和结束 ?>,实际上会调用 HTML 格式化程序代码,因为它将被视为 PHP 文件中的 HTML。

如果您在此处发布完整的文件,将更容易看出错误在哪里,或者格式化程序是否存在问题。

希望有帮助。

I tried to recreate this one, but with no real success.

When I have this code, the formatter works just fine:

<?php
$val = preg_replace('/<\/?div.*?>/', '', str_replace("<br />", " - ", $item -> getItemName()));
?>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文