URL和preg_match(再次) [英] URLs and preg_match (again)

查看:86
本文介绍了URL和preg_match(再次)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我找到了一段时间帮忙(2002年10月9日)到

的线程给我这样的模式:


`( ?((F | HT)TP://)(?([^ @:] +)([^ @] +)@)([^:\ /])+(:\d +)(\\ \\ / [^ \ s] +)?)`i


好​​的,这一切都很好用,直到在结尾处使用URL为止

sentance。我假设某种程度上我需要一个负面的预测,

但是我无法绕过这一个...


想要只匹配网址...


$ string =" ... http://www.example.com." ;;

$ string =" ... http://www.example.com/." ;;

$ string =" ... http://www.example.com/page1.html? " ;;

$ string =" ... http://www.example.com/info.php?id=4 !" ;;

等..


当我不想要它时,上面的模式是从每个字符串中拉出最后一个字符。不幸的是,URL可以_anything_有效,而我不会控制它的输入方式。任何人都可以帮忙吗?


TIA


-

Justin Koivisto - sp ** @ koivi.com

PHP海报:请使用comp.lang.php获取与PHP相关的问题,
$ b不建议使用$ b alt.php *组。

SEO竞赛联盟: http://seo.koivi.com/

OK, I found a thread that help out from a while back (Oct 9, 2002) to
give me this pattern:

`(((f|ht)tp://)(([^@:]+)([^@]+)?@)?([^:\/])+(:\d+)?(\/[^\s]+)?)`i

OK, all is well and good with this until the URL is used at the end of a
sentance. I am assuming that I will need a negative lookahead somehow,
but I just can''t wrap my mind around this one...

Want to match only the URL...

$string="... http://www.example.com.";
$string="... http://www.example.com/.";
$string="... http://www.example.com/page1.html?";
$string="... http://www.example.com/info.php?id=4!";
etc...

The pattern above is pulling the last character from each string when I
don''t want it. Unfortunately, the URL can be _anything_ valid, and I
don''t have control of how it will be input. Can anyone help with this?

TIA

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
SEO Competition League: http://seo.koivi.com/

推荐答案

string =" ... http://www.example。 com。" ;;
string="... http://www.example.com.";


string =" ... http://www.example.com/." ;;
string="... http://www.example.com/.";

< br>

string =" ... http://www.example.com/page1.html?" ;;
string="... http://www.example.com/page1.html?";


这篇关于URL和preg_match(再次)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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