function='thumb1(@me,200,150)'/]这个@me接收的是一个图片的路径地址比如:/uploads/allimg/111014/111014144214.jpg
我想用这个函数完成的功能是/uploads/allimg/111014/111014144214_200_150.jpg这样的函数要怎么写啊,我是初学者请多多关照

解决方案 »

  1.   

    什么意思,拼接到一起么?<?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;
      

  2.   


    $str='/uploads/allimg/111014/111014144214.jpg';function thumb1($me,$h,$m)
    {
    $instr = '_'.$h.'_'.$m.'.';
    return str_replace('.',$instr,$me);
    }echo thumb1($str,200,150);
      

  3.   

    也不完全对,如果图片名字是类似aaa.tmp.jpg这样的名字时,就是错误的,而这样的名字时合法的。。
      

  4.   

    $str='/uploads/allimg/111014/111014144214.jpg';function thumb1($me,$h,$m)
    {
        $instr = '_'.$h.'_'.$m.'.';
        return preg_replace("/(.*)\.(jpg|jpeg|map|gif|png)/i","$1".$instr."$2",$me);
    }echo thumb1($str,200,150);