Jump to content

Split URL and specify variable


Petsmacker

Recommended Posts

What I'm trying to do is turn a URL like this:

http://www.blabla.com/file.php?t=5&y=4&page=1

 

Into:

http://www.blabla.com/file.php?t=5&y=4

 

The URL will be in a string. I want the entire 'page' variable removed from the URL. Bear in mind the page variable could be anywhere in the URL.

How could this be done? Hope you can help.

Link to comment
https://forums.phpfreaks.com/topic/38063-split-url-and-specify-variable/
Share on other sites

Fert, your solution almost works

 

$tt="http://www.tbhg.co.uk/forum/thread.php?t=8&page=100";
$url=preg_replace("/&page=[0-9]/","",$tt);
echo "$tt<br>$url";

 

Comes out as:

http://www.tbhg.co.uk/forum/thread.php?t=8&page=166

http://www.tbhg.co.uk/forum/thread.php?t=866

 

It only removes the first number, the problem being that the page number could be anything to infinity.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.