+ -
当前位置:首页 → 问答吧 → 这样的函数怎么写呢?

这样的函数怎么写呢?

时间:2011-10-15

来源:互联网

function='thumb1(@me,200,150)'/]

这个@me接收的是一个图片的路径地址比如:/uploads/allimg/111014/111014144214.jpg
我想用这个函数完成的功能是/uploads/allimg/111014/111014144214_200_150.jpg

这样的函数要怎么写啊,我是初学者请多多关照

作者: netkee   发布时间: 2011-10-15

什么意思,拼接到一起么?

PHP code
<?php
function thumb($dir,$height='100',$width='100'){
   $pos = strripos($dir,'.');
   $sub = substr($dir,$pos);
   $presub = substr($dir,0,(strlen($dir)-strlen($sub)-1));
   $result = $presub."_".$height."_".$width.$sub;
   return $result;
}

$name = "/uploads/allimg/111014/111014144214.jpg";
$modiName = thumb($name,'220','300');
echo $modiName;

作者: ohmygirl   发布时间: 2011-10-15

没人给看看吗

作者: netkee   发布时间: 2011-10-15

PHP code

$str='/uploads/allimg/111014/111014144214.jpg';

function thumb1($me,$h,$m)
{
    $instr = '_'.$h.'_'.$m.'.';
    return str_replace('.',$instr,$me);
}

echo thumb1($str,200,150);

作者: heyli   发布时间: 2011-10-15

相关阅读 更多