Smarty 用双引号替换文本
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确实知道 HTML 宽度/高度属性中的“em”单位无效,对吗? 这只是CSS。
You do know ‘em’ units in HTML width/height attributes aren't valid, right? That's CSS only.
我的正则表达式不是最好的,或者我会给你一个更好的匹配器,但也许使用你通过正则表达式替换所拥有的东西会起作用。
其他匹配器尝试
我目前无法使用我的 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.
other matchers to try
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.
使用 Aggiorno 的智能搜索和替换,您可以这样做:
搜索模式:
替换模式:
当您单击“搜索”按钮时,在应用替换之前所有出现的情况都会突出显示,以便您可以进行进一步检查,之后您可以放心地应用替换。
With Aggiorno's Smart Search and Replace you can do it like this:
Search Pattern:
Replace Pattern:
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.