Skip to content

Instantly share code, notes, and snippets.

@roelven
Created April 19, 2010 12:25
Show Gist options
  • Save roelven/370983 to your computer and use it in GitHub Desktop.
Save roelven/370983 to your computer and use it in GitHub Desktop.
Fixes a (long) link description to fit your shortened printed string
<?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