search
HomeBackend DevelopmentPHP ProblemHow to remove url parameters in php regular

php regular method to remove url parameters: first create a PHP sample file; then use the regular expression "preg_replace('/&?return=[^&]*/', '', $old_url); ” to remove it.

How to remove url parameters in php regular

Recommended: "PHP Video Tutorial"

Specific questions:

Removing URL parameters using PHP

I have some links in a powerpoint presentation and for some reason when these links are clicked it adds a return parameter to the URL. Well, that return parameter caused the MVC pattern of my Joomla website to be messed up.

So, what is the effective way to remove this return parameter using PHP? ?

Solution:

1. Use parse_url() to parse the URL into an array

2. Extract the query part and use parse_str() to parse it Decomposed into an array

3. Remove the query parameters required by unset() from the array using http_build_query()

4. Rebuild the original URL

The quick and dirty thing is Use string search/replace and/or regular expressions to eliminate the value.

Regular expression such as:

$new_url = preg_replace('/&?return=[^&]*/', '', $old_url);

The above is the detailed content of How to remove url parameters in php regular. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.