Home > Backend Development > PHP Problem > How to get link suffix in php

How to get link suffix in php

王林
Release: 2023-02-24 16:18:02
Original
4342 people have browsed it

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);
Copy after login

The running result is as follows:

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

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 );
Copy after login

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;],"."),".");
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template