插件10:文本简化

<?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 字符串变量,包含一个字符序列,标志字符串删除部分。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值