In PHP, get the file suffix name? _php Tips

Source: Internet
Author: User
The first type of method is done using arrays. First cut the file name to a group, and then find a way to get the last element of the array OK. The second type of method is done through the processing of strings, and another method is to use the PathInfo () function.
Copy Code code as follows:

$pic = ' Abc.3434.342.12123.123.exe ';
$pics = Explode ('. ', $pic);

/* Get the total number of arrays, and then take the last one * *
echo $num = count ($pics);
Echo ' <br> '. $pics [$num-1];

/* Traverse Array to get the last element * *
foreach ($pics as $value)//2
{
$a = $value;
}
echo $a. ' <br> ';
/* Direct output array last element * *
Echo End ($pics);
Echo ' <br> ';
/* The last element of the group, note the difference with end () * *
echo Array_pop ($pics);
/* First order the array according to the key value, then the first element.
Krsort ($pics);
echo Array_shift ($pics);
Echo ' <br> ';

/*pathinfo () function returns the value of the extension index corresponding to the value * *
$res = PathInfo ($pic); 5
Var_dump ($res);
echo $res [' extension ']. <br> ';

/* String intercept, take the last three bits can be * *
Echo substr ($pic,-3, 3);

We can see that a problem has n a variety of solutions, in the process of doing the same, the solution is always there, for some novice, must adhere to, so as to learn good PHP!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.