/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function get_links($string) { $patron='/\<a href\=(.*?)\>(.*?)\<\/a\>/is'; return $coincidencias[0]; }; function get_links_text($string) { $patron='#[^<ref=">]http\:\/\/([^"<>]*)#is'; return $coincidencias[0]; }; function redlink($link,$largopartes){ $patron='/\<a href\=(.*?)\>(.*?)\<\/a\>/i'; $s='/\<a href\=(.*?)\>(.*?)\<\/a\>/se'; $r='"<a href=$1>".substr("$2",0,"$largopartes")."...".substr("$2","-$largopartes")."</a>"'; else $r='"<a href=$1>$2</a>"'; return $t; } function redlink2($link,$largopartes){ else $r='<a href="'.$link.'">'.$link.'</a>'; return $r; } $cadena=' um fringilla commodo, magna metus tempus justo, quis eleifend enim ante vel nisl. Nam tellus ligula, semper eu, pretium et, placerat sit amet, justo. Phasellus sagittis faucibus orci. Phasellus ultricies scelerisque nulla. Quisque metus. Aliquam leo dolor, pellentesque eu, cursus sollicitudin, porta a, velit. hola http://www.akjhas.dasa/asdasda/asasa/asasa/asasasas/asas.pl <br><a href="http://www.google.com.ar">Este es un magnÃfico buscador y en él hay de todo</a> Nunc pulvinar. In porta nisl vitae magna. Nunc justo libero, feugiat at, dignissim sed, interdum eleifend, est. In ornare pellentesque odio. Ut mauris. Donec ornare vestibulum urna. Vestibulum et massa. Integer viverra, nisl ac congue elementum, nisi felis dignissim sapien, et adipiscing nisl urna a ligula. In mattis imperdiet dui. Fusce tincidunt mauris sed massa. Aenean at nisl. Sed enim ante, aliquam non, sagittis non, consequat et, dui. Aliquam faucibus adipiscing lacus. Praesent sem velit, scelerisque sit am '; $links=get_links($cadena); $urls=get_links_text($cadena); foreach($links as $v){ $replace[]=redlink($v,15); } foreach($urls as $v){ $replace[]=redlink2($v,15); }