我有一个字符串从字符串中提取一个子串在PHP
$url = "http://www.example.com/index.php?1234567"
我只希望子“http://www.example.com”,即提取高达子的第三次出现正斜杠字符。
在此先感谢
我有一个字符串从字符串中提取一个子串在PHP
$url = "http://www.example.com/index.php?1234567"
我只希望子“http://www.example.com”,即提取高达子的第三次出现正斜杠字符。
在此先感谢
试试这个
<?php
$url = 'http://www.example.com/index.php?1234567';
print_r(parse_url($url));
?>
你需要看看parse_url()
$link = "http://www.something.cmo/sdfsdf";
$str = explode("/", $link);
echo $str[2]; // is string without sub
如果你的代码得到纠正,它会打印'www.something.cmo',否则PHP会报错。 – flowfree
你应该签: http://php.net/manual/en/function.parse-url.php
parse_url()
将返回一个关联数组,您应该查找键值为host
和scheme
的值以获取所需内容。
亲切的问候,
博
可能重复http://stackoverflow.com/search?q=[php]+is%3Aanswer+parse_url – Gordon
-1 [问一个问题之前,请先做好功课] (http://stackoverflow.com/questions/ask-advice)。即使不知道有'parse_url'这个问题在以前的一些研究中不会很难独立解决。 – Gordon
戈登,因为我是新来的PHP我真的不知道这样的功能存在,为什么我在这里发布 – tariq