正则表达式在PHP中的任何网址或链接 [英] regex any urls or links in php

查看:122
本文介绍了正则表达式在PHP中的任何网址或链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正则表达式来捕获php中的任何url:

I have that regex to catch any url in php :

((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)

但它没有抓到完整的网址.. ...例如

but it didn't catch the full url ..... for Example

此处:

http://v12.lscache6.c.youtube.com/videoplayback?app=youtube_gdata&devkey=AX8iKz393pCCMUL6wqrPOZoO88HsQjpE1a8d1GxQnGDm&el=videos&upn=0K3DA3wYhjI&uaopt=no-save&source=youtube&itag=18&id=ab59b1e9554eca6d&ip=0.0.0.0&ipbits=0&expire=1339342342&sparams=id,itag,source,uaopt,upn,ip,ipbits,expire&signature=5026BE137B41D5CD9785E752D1892903D432974C.BA1D4E0C138210B2275391A2A3D469E582183621&key=yta1&cms_redirect=yes

它只捕获:

http://v12.lscache6.c.youtube.com/videoplayback?app=youtube_gdata&devkey= AX8iKz393pCCMUL6wqrPOZoO88HsQjpE1a8d1GxQnGDm&安培; EL =视频&安培; UPN = 0K3DA3wYhjI&安培; uaopt =无保存&安培;源= YouTube和安培; ITAG = 18和ID = ab59b1e9554eca6d&安培; IP = 0.0.0.0&安培; ipbits = 0&安培;到期= 1339342342&安培; sparams = ID

那么我需要什么来捕捉完整的网址?

So what do I need to catch the full url?

推荐答案

你需要在正则表达式中添加一个昏迷字符:

You need to add a coma character in regex:

你的正则表达式已修复:

Your regex fixed:

((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@,.\w_]*)#?(?:[\w]*)?))

验证正则表达式的好网站: Rubular

Good site to validate regex: Rubular

如果要将URL分解为部分,可以使用parse_url()PHP功能

If you want decompose the URL into a parts, you can use the parse_url() PHP function

这篇关于正则表达式在PHP中的任何网址或链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆