Petsmacker Posted February 11, 2007 Share Posted February 11, 2007 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 More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Your question is not very clear. Once the page is in the url you cannot remove it from the current url. If you want to removed it from your links, just do so. Link to comment https://forums.phpfreaks.com/topic/38063-split-url-and-specify-variable/#findComment-182198 Share on other sites More sharing options...
fert Posted February 11, 2007 Share Posted February 11, 2007 $url=preg_replace("/page=[0-9]/","",$url); I haven't tested that, but it should work. Link to comment https://forums.phpfreaks.com/topic/38063-split-url-and-specify-variable/#findComment-182199 Share on other sites More sharing options...
Petsmacker Posted February 11, 2007 Author Share Posted February 11, 2007 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. Link to comment https://forums.phpfreaks.com/topic/38063-split-url-and-specify-variable/#findComment-182230 Share on other sites More sharing options...
fert Posted February 11, 2007 Share Posted February 11, 2007 $url=preg_replace("/&page=[0-500000]/","",$url); that'll work for every number in the range of 0 to 500000 Link to comment https://forums.phpfreaks.com/topic/38063-split-url-and-specify-variable/#findComment-182240 Share on other sites More sharing options...
Petsmacker Posted February 11, 2007 Author Share Posted February 11, 2007 Doesn't work (And I did change the variable at the end of the example you gave to $tt) Link to comment https://forums.phpfreaks.com/topic/38063-split-url-and-specify-variable/#findComment-182245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.