Dont Stop til You get enough php to get the suffix name of the file?

Source: Internet
Author: User
The first class of methods is done using arrays. First cut the file name into the array, and then find a way to get the last element of the list is OK. The second class of methods is done through the processing of strings, and one method is to use the PathInfo () function.

Copy the Code code as follows:


$pic = ' Abc.3434.342.12123.123.exe ';
$pics = Explode ('. ', $pic);
/* Get the total number of arrays and take the last one */
echo $num = count ($pics);
Echo '
'. $pics [$num-1];
/* Iterate through the array to get the last element */
foreach ($pics as $value)//2
{
$a = $value;
}
echo $a. '
';
/* Directly output the last element of the array */
Echo End ($pics);
Echo '
';
/* The last element of a single array, note the difference from end () */
echo Array_pop ($pics);
/* First arrange the array in reverse order of key values and then single out the first element */
Krsort ($pics);
echo Array_shift ($pics);
Echo '
';
/*pathinfo () function returns the value of the extension index of the value */
$res = PathInfo ($pic); 5
Var_dump ($res);
echo $res [' extension ']. '
';
/* String intercept, take the last three bits */
Echo substr ($pic,-3, 3);


You can see a problem has n many solutions, in the process of doing the same time, the solution is always there, for some novice, must adhere to, so that the PHP learning good!

The above describes the dont stop til you get enough php to get the file suffix name? , including dont stop til you get enough content, want to be interested in PHP tutorial friends helpful.

  • 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.