【问题标题】:Detection - the title of the URL and the URL检测 - URL 的标题和 URL
【发布时间】:2011-09-30 23:43:43
【问题描述】:

如何检测文本和标题中是否有任何URL(如果有)?

如果有,那么它应该改变URL:

来自:http://stackoverflow.com

进入:

<detected:url="http://stackoverflow.com"/>

我还需要像这个例子一样从外部链接中检索标题:

<title:http://stackoverflow.com/="the actual title from the stackoverflow"/>

【问题讨论】:

  • 这取决于。所有 URL 都以“http”开头吗?什么表示 URL 的标题?
  • @tandu 并不是因为它会解析用户发布的数据。 Title 是从 标签中检测到的站点 url 标题。
  • 这应该是 XML 吗?如果是这样,则它不是有效的 XML。
  • @icktoofay 呵呵,不,不是 XML:p
  • 您从什么检测 URL:HTML? XML?文字?

标签: php url detection


【解决方案1】:

这是针对单个 URL 的情况:

$url = "http://www.stackoverflow.com/";

$check_result = get_detected_and_title( $url );


function get_detected_and_title( $url )
{
    $detected = '<detected:url="'.$url.'"/>';
    $title = '';
    $tmp_html = file_get_contents( $url );
    preg_match('/<title>(.*)<\/title>/', $tmp_html, $res);
    $title = '<title:'.$url.'="'.$res[1].'"/>';

    return array( $detected, $title );
}

实际上,在浏览了 SO 的页面后,我认为这更接近您所寻找的。虽然需要一些调整:How to mimic StackOverflow Auto-Link Behavior

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 2011-12-22
    • 1970-01-01
    • 2013-02-06
    • 2010-12-04
    • 1970-01-01
    相关资源
    最近更新 更多