Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detection - the title of the URL and the URL

Tags:

url

php

detection

How to detect, if there is any URL in the text and title it has (if any)?

If there is one, then it should change the URL:

from: http://stackoverflow.com

into:

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

I need also to retrieve titles from external links like this example:

<title:http://stackoverflow.com/="the actual title from the stackoverflow"/>
like image 695
Lucas Avatar asked Nov 27 '25 02:11

Lucas


1 Answers

This is for single URL case:

$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 );
}

Actually, after looking through SO's pages, I think this is more close to what you looking for. Although it needs some adjustment: How to mimic StackOverflow Auto-Link Behavior

like image 103
ariefbayu Avatar answered Nov 28 '25 15:11

ariefbayu