function get_first_message($link) { $res = mysql_query("SELECT `message`, `created` FROM `tweet` ORDER BY `created` DESC LIMIT 1", $link); if ($row = mysql_fetch_assoc($res)) { $message = $row['message']; $message = linkify_html($message); return array('message' => $message, 'created' => $row['created']); } return false; }
function linkify_html($text) { $text = preg_replace('/'/', ''', $text); // IE does not handle ' entity! $section_html_pattern = '%# Rev:20100913_0900 github.com/jmrware/LinkifyURL # Section text into HTML <A> tags and everything else. ( # $1: Everything not HTML <A> tag. [^<]+(?:(?!<a\\b)<[^<]*)* # non A tag stuff starting with non-"<". | (?:(?!<a\\b)<[^<]*)+ # non A tag stuff starting with "<". ) # End $1. | ( # $2: HTML <A...>...</A> tag. <a\\b[^>]*> # <A...> opening tag. [^<]*(?:(?!</a\\b)<[^<]*)* # A tag contents. </a\\s*> # </A> closing tag. ) # End $2: %ix'; return preg_replace_callback($section_html_pattern, '_linkify_html_callback', $text); } function _linkify_html_callback($matches) { if (isset($matches[2])) { return $matches[2]; } return linkify($matches[1]); } // Linkify and display the linkify.html file. $text = file_get_contents('linkify.html'); preg_match('/^(.*?<body[^>]*>)(.*)$/si', $text, $matches); $text = $matches[2]; echo $matches[1] . linkify_html($text);