Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 链接字符串中间的URL_Php_Html - Fatal编程技术网

Php 链接字符串中间的URL

Php 链接字符串中间的URL,php,html,Php,Html,不知道如何在字符串中检测URL并返回链接。范例 $text='访问www.example.com example.com example.net'; echo$文本 会回来吗 访问www.example.com example.com 等等 您可以使用正则表达式,也可以在空格中分解$text字符串,然后使用子字符串检查每个分解的单词,如果它们以http://、https://开头或以.com、.net、.org结尾,并将该字符串包装在链接中,我就是这样做的 它将回显http://google.c

不知道如何在字符串中检测URL并返回链接。范例

$text='访问www.example.com example.com example.net'; echo$文本

会回来吗

访问www.example.com example.com 等等


您可以使用正则表达式,也可以在空格中分解$text字符串,然后使用子字符串检查每个分解的单词,如果它们以http://、https://开头或以.com、.net、.org结尾,并将该字符串包装在链接中

,我就是这样做的

它将回显
http://google.com
来自

www.website.com和example.com但是现在 www.website.com


我会使用本网站或谷歌上的搜索来查找stackoverflow上的最高评分答案,这为我解决了这个问题。但这可能只是个人偏好。你也可以继续怀疑和等待,这里的用户开始提供黑客代码和半成品解决方案纯粹是巧合,因为他们刚刚发现你要求它。可能重复的
<?php
$x = "www.website.com and example.com and 
      even http://google.com and now www.website.com I could go on forever";

 $start = strpos($x, 'http://');
    for($i=$start; $i < strlen($x); $i++){

        if(strpos($x, '.com') == true) {
            $str = strpos($x, '.com');
                echo $x[$i];
        if($x[$i] === ' '){
            break;
        }
    }
}