Home  >  Article  >  Backend Development  >  How to get link suffix in php

How to get link suffix in php

王林
王林Original
2019-09-21 17:57:064259browse

How to get link suffix in php

How to get the suffix (php) of the executed file my.order.php, 2 methods are listed for reference only:

First get it through parse_url Link information:

<?php
$link="http://www.xxx.com/testweb/my.order.php?abcd=111@qqq=222";
$parseUrl_link=parse_url($link);
print_r($parseUrl_link);

The running result is as follows:

Array
(
    [scheme] => http
    [host] => www.xxx.com
    [path] => /testweb/my.order.php
    [query] => abcd=111@qqq=222
)

Then get the file extension based on the obtained (path) information.

Method 1

Idea: Read the path information through pathinfo and the PATHINFO_EXTENSION parameter, and the output is the file extension.

echo pathinfo($parseUrl_link[&#39;path&#39;],PATHINFO_EXTENSION );

Method 2

Idea: Get the information including the last "." and the following through strrchr, and then delete the "." on the left. , the output is the file extension.

echo ltrim(strrchr($parseUrl_link[&#39;path&#39;],"."),".");

The above is the detailed content of How to get link suffix in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to paginate in PHPNext article:How to paginate in PHP