如何从 php 中的用户输入中删除 http、https、slash、www
How do I remove http, https ,slash,www from user input in php
我想删除
http://
ftp://
https://
ftps://
http://www.
https://www.
ftp://www.
ftps://www.
www.
如果上面有人使用域 url,我们想删除。
我们只想显示 url
domain.com
我们尝试 preg_replacefor http 和 https。它对两者都很好,但它不起作用。如果找到 www 或 ftp
preg_replace('#^https?://#', '', $str)
可能更好,但应该这样做:
$result = preg_replace('#^(https?://|ftps?://)?(www.)?#', '', $str);
- (http with optional ? s :// OR | ftp with optional ? s ://) 和两个可选的 ?
- www.可选 ?
这是一个更简单的正则表达式:
$result = preg_replace('%^(htt|ft)ps?://|(www\.)%i', '', $url);
%i
(不敏感)对于 Https
等情况
我想删除
http://
ftp://
https://
ftps://
http://www.
https://www.
ftp://www.
ftps://www.
www.
如果上面有人使用域 url,我们想删除。 我们只想显示 url
domain.com
我们尝试 preg_replacefor http 和 https。它对两者都很好,但它不起作用。如果找到 www 或 ftp
preg_replace('#^https?://#', '', $str)
可能更好,但应该这样做:
$result = preg_replace('#^(https?://|ftps?://)?(www.)?#', '', $str);
- (http with optional ? s :// OR | ftp with optional ? s ://) 和两个可选的 ?
- www.可选 ?
这是一个更简单的正则表达式:
$result = preg_replace('%^(htt|ft)ps?://|(www\.)%i', '', $url);
%i
(不敏感)对于 Https
等情况