Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.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
Javascript PHP检查文本框是否包含链接_Javascript_Php_String_Codeigniter_Variables - Fatal编程技术网

Javascript PHP检查文本框是否包含链接

Javascript PHP检查文本框是否包含链接,javascript,php,string,codeigniter,variables,Javascript,Php,String,Codeigniter,Variables,我想知道是否有可能检查文本框是否包含任何链接。如果可以从字段中选择该链接 我试过这样做,但问题是我不能选择整个链接,而且查询非常不精确 $a = 'Lorem ipsum dolor sit amet, consetetur sadipscing www.loremipsum.com/asd/fgh/jkl elitr, sed diam '; if (strpos($a, 'www.') !== false) { ech

我想知道是否有可能检查文本框是否包含任何链接。如果可以从字段中选择该链接

我试过这样做,但问题是我不能选择整个链接,而且查询非常不精确

$a = 'Lorem ipsum dolor sit amet, consetetur sadipscing www.loremipsum.com/asd/fgh/jkl elitr, sed diam ';

                if (strpos($a, 'www.') !== false) {
                    echo 'true';
                }
再次解释一下:

我有一个文本字段,可以包含评论,也可以包含链接。我需要从该字段中选择正确的链接,并将其单独保存在变量中

我不想让你编写我的代码,但如果有人知道实现这一点的函数或方法,那就太好了


谢谢大家!

这里有一个与www.whatever匹配的正则表达式


您可以使用strstr来代替strpos,它返回下一个单词。

尝试使用正则表达式,如中的顶级投票答案,以及
preg\u match
preg\u match\u all
来检索URL。可能重复wow,谢谢,它确实有效。但是我怎样才能只输出链接而不是整个数组呢?谢谢。我用for循环解决了这个问题。因为它可以是多个链接。但是第一个[0]不是没有必要吗?
<?php

$string = 'Lorem ipsum dolor sit amet, consetetur sadipscing www.loremipsum.com/asd/fgh/jkl elitr, sed diam ';
$regex= '#www\.\S+#';

preg_match_all($regex,$string, $matches);
var_dump($matches);
#https?:\/\/\S+#