Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<?php
function shortenLinksCallback($match){
return "<a href='$match[0]'>" . preg_replace(
'~(.{40}[a-z0-90]*.).{10,}([ˇa-z0-9;].*.{10,})~i',
'\\1...\\2',
$match[0]
) . "</a>";
}
/**
* @param string
* @return string
*/
function shortenLinks($text){
static $chars = "][;#%&+./0-9:=?a-z_~-";
return preg_replace_callback (
"(\\bhttps?://[$chars]+\\.[$chars]*[][+/0-9=a-z_~;])i",
'shortenLinksCallback',
htmlSpecialChars($text)
);
}
?>
<?php
echo shortenLinks("xxx https://net-raft.com/Questions/869/how-to-detect-the-type-of-a-device-pc-mobile-using-php-/869 xxx");
// shorten if link is greater than 62 signs
?>
</body>
</html>
The most helpful PHP solutions
detect browser phpPHP Click to see more ... 4.6K 408