简体   繁体   English

Smarty如何解析模板文件中的URL

[英]Smarty how to parse URL in template file

How would I translate this PHP statement: $domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST)); 我将如何翻译此PHP语句: $domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST)); to a smarty function such as: {$url|str_ireplace:'something':'etc'} 到一个聪明的函数,例如: {$url|str_ireplace:'something':'etc'}

I want to print $domain in this case. 在这种情况下,我想打印$ domain。 $url is a smarty variable that is set for a certain URL. $ url是为某个URL设置的智能变量。 How do I do this? 我该怎么做呢?

You can pipe multiple modifiers, to first extract the host and then strip the www. 您可以通过管道传递多个修饰符,以首先提取主机,然后剥离www. :

{$url|parse_url:$smarty.const.PHP_URL_HOST|replace:'www.':''}

So for: 因此对于:

$url = 'http://www.example.com/foo/bar.html';

It prints: 它打印:

example.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM