[英]Remove website http/https while adding URL from website
0 0
In my custom field, users add their site URls.在我的自定义字段中,用户添加了他们的网站 URls。 I want to display them like this example.com not http//example.com/.
我想像这个例子一样显示它们。com 不是 http//example.com/。 I want to remove the http/https.
我想删除 http/https。 This is just for the display purpose.
这只是为了显示目的。
<a href="<?php echo($context['user_data']['website']) ?>" rel="nofollow" target="_blank"><?php echo $context['user_data']['website']; ?></a>
While display, it displays the entire URL like http://example.com in a link.在显示时,它会在链接中显示整个 URL,如http://example.com 。 I want to remove the protocol and display like example.com
我想删除协议并显示如 example.com
Thanks谢谢
You can use parse_url()
, and ['host']
:您可以使用
parse_url()
和['host']
:
<a href="<?php echo($context['user_data']['website']) ?>" rel="nofollow" target="_blank">
<?php echo parse_url($context['user_data']['website'])['host']; ?>
</a>
You maybe should test if parse_url() return an array before to access ['host'].您可能应该在访问 ['host'] 之前测试 parse_url() 是否返回一个数组。
Documentation: https://www.php.net/manual/en/function.parse-url.php文档: https://www.php.net/manual/en/function.parse-url.php
$parse = parse_url($context['user_data']['website'])
echo $parse['host'].$parse['path'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.