smarty 字符串连续替换两次
smarty string replace two times in a row
大家好。
我在创建 https 链接方面遇到了一些问题,我得到的唯一入口点是聪明的,所以我的想法是简单地搜索字符串 http
并将其替换为 https
,但是,为了确定,我还想将字符串 httpss
转换为 https
以处理那些已经用作 https 的链接。
其实我是这样做的:
{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )|replace:"http":"https"}
有没有办法在同一行中添加另一个字符串替换?
我的意思是:
{($link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )|replace:"http":"https")|replace:"httpss":"https"}
我一年只使用 smarty 两次,所以我在这方面不是很专业,我不想增加复杂性(明年我将无法阅读);)
Smarty 中有更好的选项(例如regex_replace
),但是为了更正确的替换,您不能直接替换整个协议吗?
{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )|replace:"http://":"https://"}
这样你就可以确定它不会替换 link 中包含单词 http
的部分(不在协议中),而只会替换 http://
links 将被替换
大家好。
我在创建 https 链接方面遇到了一些问题,我得到的唯一入口点是聪明的,所以我的想法是简单地搜索字符串 http
并将其替换为 https
,但是,为了确定,我还想将字符串 httpss
转换为 https
以处理那些已经用作 https 的链接。
其实我是这样做的:
{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )|replace:"http":"https"}
有没有办法在同一行中添加另一个字符串替换? 我的意思是:
{($link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )|replace:"http":"https")|replace:"httpss":"https"}
我一年只使用 smarty 两次,所以我在这方面不是很专业,我不想增加复杂性(明年我将无法阅读);)
Smarty 中有更好的选项(例如regex_replace
),但是为了更正确的替换,您不能直接替换整个协议吗?
{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )|replace:"http://":"https://"}
这样你就可以确定它不会替换 link 中包含单词 http
的部分(不在协议中),而只会替换 http://
links 将被替换