[英]How to turn www.mydomain.com/page/user/756890 to www.mydomain.com in PHP
How could I replace the URL of a string from this:我怎么能从这个替换字符串的 URL:
798| 451.263.160.11| CONNECT | http://www.mywebsite.com/pages/user/678976546789 | China | 22 min
To this in PHP:在 PHP 中:
798| 451.263.160.11| CONNECT | http://www.mywebsite.com | China | 22 min
Thanks guys :)谢谢你们 :)
[NOTE: The text is from a file] [注意:文本来自文件]
I'm not sure what you mean by "register file", but it looks like you're trying to do a regex replacement .我不确定您所说的“注册文件”是什么意思,但看起来您正在尝试进行正则表达式替换。
$input = '798| 451.263.160.11| CONNECT | http://www.mywebsite.com/pages/user/678976546789 | China | 22 min';
$search_for = 'http://www.mywebsite.com';
$output = preg_replace('/' . preg_quote($search_for, '/') . '([^ ]+)/', $search_for, $input);
The code above will search for the string you provide, and remove all characters until the next space.上面的代码将搜索您提供的字符串,并删除所有字符直到下一个空格。
You can find out more about regex in PHP using the manual:您可以使用手册找到有关 PHP 中正则表达式的更多信息:
http://php.net/preg_replace http://php.net/preg_replace
http://php.net/manual/en/reference.pcre.pattern.syntax.php http://php.net/manual/en/reference.pcre.pattern.syntax.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.