Smarty 用双引号替换文本

发布于 2024-07-08 23:50:46 字数 273 浏览 3 评论 0原文

我在 smarty(php 模板系统)变量 $test 中有以下字符串:

<img height="113" width="150" alt="Sunset" src="/test.jpg"/>

我想将“em”添加到高度和宽度,如下所示:

{$test|replace:'" w':'em" w'|replace:'" a':'em" a'}

但这不起作用...问题和解决方案是什么?

I have the following string in the smarty (php templating system) variable $test:

<img height="113" width="150" alt="Sunset" src="/test.jpg"/>

I want to add "em" to the height and width like this:

{$test|replace:'" w':'em" w'|replace:'" a':'em" a'}

But this doesn't work... What's the problem and the solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

梦断已成空 2024-07-15 23:50:46

您确实知道 HTML 宽度/高度属性中的“em”单位无效,对吗? 这只是CSS。

You do know ‘em’ units in HTML width/height attributes aren't valid, right? That's CSS only.

寻找我们的幸福 2024-07-15 23:50:46

我的正则表达式不是最好的,或者我会给你一个更好的匹配器,但也许使用你通过正则表达式替换所拥有的东西会起作用。

{$test|regex_replace:'/".w/':'em" w'|regex_replace:'/".a/':'em" a'}

其他匹配器尝试

'/\".w/'
'/".*w/'
'/\".*w/'

我目前无法使用我的 smarty 网站,但我首先从替换值中删除“,看看是否存在错误,然后将其从匹配器中删除并仅查找高度/宽度,

否则如果可以的话我会用 PHP 进行替换。

my regex isn't the greatest, or i'd give you a better matcher, but maybe using what you have through the regex replace would work.

{$test|regex_replace:'/".w/':'em" w'|regex_replace:'/".a/':'em" a'}

other matchers to try

'/\".w/'
'/".*w/'
'/\".*w/'

i can't play with my smarty sites at the moment, but i'd first remove the " from the replacement value, to see if the bug is there, then remove it from the matcher and just look for height/width.

otherwise i'd do the replace in PHP if you can.

笑咖 2024-07-15 23:50:46

使用 Aggiorno 的智能搜索和替换,您可以这样做:

搜索模式:

<img height="$h" width="$w" $attributes/>

替换模式:

<img height="$[h]em" width="$[w]em" $attributes"/>

当您单击“搜索”按钮时,在应用替换之前所有出现的情况都会突出显示,以便您可以进行进一步检查,之后您可以放心地应用替换。

With Aggiorno's Smart Search and Replace you can do it like this:

Search Pattern:

<img height="$h" width="$w" $attributes/>

Replace Pattern:

<img height="$[h]em" width="$[w]em" $attributes"/>

When you click the "Search" button, all the occurrences are highlighted before applying the replacement so you can do further checking, after that you can apply the replacement confidently.

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