从php中的字符串中提取子字符串

时间:2012-05-25 11:32:50

标签: php

我有一个字符串

$url = "http://www.example.com/index.php?1234567"

我只想要子字符串“http://www.example.com”,即将子字符串提取到第三次出现的正斜杠字符。

提前致谢

4 个答案:

答案 0 :(得分:2)

您需要查看parse_url()

答案 1 :(得分:2)

试试这个

<?php
$url = 'http://www.example.com/index.php?1234567';

print_r(parse_url($url));

?>

答案 2 :(得分:1)

$link = "http://www.something.cmo/sdfsdf";
$str  = explode("/", $link);

echo $str[2]; // is string without sub

答案 3 :(得分:1)

你应该结帐: http://php.net/manual/en/function.parse-url.php

parse_url()会返回一个关联数组,您应该查找键hostscheme的值以获得所需内容。

亲切的问候,

相关问题