<?php // Plug-in 10: Shorten Text
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$text = "http://rover.ebay.com/rover/1/711-53200-19255-0/1?type=3&campid=5336224516&toolid=10001&customid=tiny-hp&ext=unicycle&satitle=unicycle";
echo "Before: <a href=\"$text\">$text</a><br /><br />";
echo "After: <a href=\"$text\">" . PIPHP_ShortenText($text, 60, "/-/-/") . "</a>";
function PIPHP_ShortenText($text, $size, $mark)
{
// Plug-in 10: Shorten Text
//
// This plug-in takes a string variable containing any
// text and then shortens it to the length supplied by
// removing text from the middle. The arguments required
// are:
//
// $text: Text to be modified
// $size: New size of the string
// $mark: String to mark position of removed text
$len = strlen($text);
if ($size >= $len) return $text;
$a = substr($text, 0, $size / 2 -1);
$b = substr($text, $len - $size / 2 + 1, $size/ 2 -1);
return $a . $mark . $b;
}
?>
插件说明:
插件10接受一个字符串变量,它代表一个需要简化的长URL地址(或其他字符串),返回简化后的URL地址,它需要用到以下参数:
$text 字符串变量,包含需要处理的文本
$size 数值变量,表示新字符串的大小
$mark 字符串变量,包含一个字符序列,标志字符串删除部分。