相关疑难解决方法(0)

正则表达式以查找字符串中的URL

有谁知道我可以用来查找字符串中的URL的正则表达式?我在Google上发现了很多正则表达式,用于确定整个字符串是否为URL,但我需要能够在整个字符串中搜索URL.例如,我希望能够找到www.google.comhttp://yahoo.com在以下字符串中:

Hello www.google.com World http://yahoo.com
Run Code Online (Sandbox Code Playgroud)

我不是在寻找字符串中的特定URL.我正在寻找字符串中的所有URL,这就是我需要正则表达式的原因.

regex string url

73
推荐指数
11
解决办法
11万
查看次数

使用PHP从字符串中提取URL

我们如何使用PHP来识别字符串中的URL并将它们存储在数组中?

explode如果URL包含逗号,则无法使用该函数,它不会给出正确的结果.

php url

33
推荐指数
3
解决办法
4万
查看次数

如何模仿堆栈溢出自动链接行为

使用PHP,我如何模仿Stack Overflow的自动链接行为(BTW非常酷)?

例如,以下URL:

http://www.stackoverflow.com/questions/1925455/how-to-mimic-stackoverflow-auto-link-behavior

转换成这个:

<a title="how to mimic stackoverflow auto link behavior" rel="nofollow" href="http://www.stackoverflow.com/questions/1925455/how-to-mimic-stackoverflow-auto-link-behavior">stackoverflow.com/questions/1925455/…</a>
Run Code Online (Sandbox Code Playgroud)

title在这种情况下,我并不真正关心属性.


还有这个:

http://pt.php.net/manual/en/function.base-convert.php#52450

转换成这个:

<a rel="nofollow" href="http://pt.php.net/manual/en/function.base-convert.php#52450">pt.php.net/manual/en/…</a>
Run Code Online (Sandbox Code Playgroud)

如何在PHP中创建类似的功能?

PS:查看我对这个问题的评论,了解更多示例和行为.

php regex string

20
推荐指数
3
解决办法
1万
查看次数

PHP查找文本中的所有链接

我想找到文本中的所有链接,如下所示:

Test text http://hello.world Test text 
http://google.com/file.jpg Test text https://hell.o.wor.ld/test?qwe=qwe Test text 
test text http://test.test/test
Run Code Online (Sandbox Code Playgroud)

我知道我需要使用preg_match_all,但只有头脑中的想法:从http | https | ftp开始搜索并在文本的空格或末尾出现的结束搜索,这就是我真正需要的所有内容,因此所有链接都可以正确找到.

任何人都可以帮助我使用php regexp模式?

我想我需要在模式结束时使用断言,但现在无法理解它们的正确用法.

有任何想法吗?感谢名单!

php regex

3
推荐指数
2
解决办法
9863
查看次数

更新功能以识别链接

我有此功能来识别和转换标签,表情符号等

function convert_text($str) {
        $regex = "/[@#](\w+)/";
    //type and links
        $hrefs = [
            '#' => 'hashtag.php?hashtag',
            '@' => 'user.php?user'
        ];

        $result = preg_replace_callback($regex, function($matches) use ($hrefs) {
             return sprintf(
                 '<a href="%s=%s">%s</a>',
                 $hrefs[$matches[0][0]],
                 $matches[1], 
                 $matches[0]
             );
        }, $str);

        //$result = preg_replace("/U\+([A-F0-9]{5})/", '\u{${1}}', $result);
        $result = preg_replace('/U\+([A-F0-9]{5})/', '<span style="font-size:30px;">&#x\\1;</span>', $result);

        return ($result);
    }
Run Code Online (Sandbox Code Playgroud)

我想,使其认识http://https://从文字和比转换为:

<a href="http://link.com">http://link.com</a> 如何在函数内部实现呢?

php regex arrays function href

1
推荐指数
1
解决办法
355
查看次数

标签 统计

php ×4

regex ×4

string ×2

url ×2

arrays ×1

function ×1

href ×1