Created
April 19, 2010 12:25
-
-
Save roelven/370983 to your computer and use it in GitHub Desktop.
Fixes a (long) link description to fit your shortened printed string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Fixes a (long) link description to fit your shortened printed string | |
// uses WordCut: http://gist.github.com/370982 | |
// @var = your full text string (function will cut this) | |
function linkfix($var) { | |
$pattern = '%(<a href=")([-/_+0-9a-z]{3,})(">)(.*?)(</a>)%i'; | |
preg_match($pattern, $var, $matches); | |
$newtext = wordCut($matches[4], 20, '...'); | |
$replace = '${1}${2}${3}'.$newtext.'${5}'; | |
$fixed = preg_replace($pattern, $replace, $var); | |
return $fixed; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment