freaky
freaky

Reputation: 294

Remove certain values anywhere form url

I want to know whether or not it is possible to remove any values from a url that is going to be passed. For instance www.example.com/dummypage1/en/var?123 now what I want to do is remove the en in the url, which will now look like www.example.com/dummypage1/var?123

Upvotes: 0

Views: 58

Answers (4)

XMehdi01
XMehdi01

Reputation: 1

Simply by using str_replace(), Remove desired word in your case en/ by replacing it with an empty string:

$url = "www.example.com/dummypage1/en/var?123";
echo str_replace('en/', '', $url);

Output:www.example.com/dummypage1/var?123

Upvotes: 0

Expedito
Expedito

Reputation: 7795

You can use explode:

$url = "www.example.com/dummypage1/en/var?123 ";
$parts = explode('/', $url);
$end = array_slice($parts, 3);
$parts = array_merge(array_slice($parts, 0, 2), $end);
$url = implode('/', $parts);

Upvotes: 1

kraysak
kraysak

Reputation: 1756

check this answer:

$url= "www.example.com/dummypage1/en/var?123";

$piece=explode('en/',$url);    // en/ is the word you want to remove..

$newurl=$piece[0].$piece[1];
echo $newurl;

echo: www.example.com/dummypage1/var?123

Upvotes: 2

Madara's Ghost
Madara's Ghost

Reputation: 175017

Have a look at parse_url(), explode() and implode().

You'll be able to do it using those three.

Upvotes: 1

Related Questions