Removing part of a string that changes


I’m not sure that this is possible, but I have a url which I’d like to check for the portion “page=1&” (see below)


If the URL has this string, then I’d like to be able to get rid of that part of the URL. The problem is that the number portion of the page= won’t be known ahead of time. I thought about chopping up the URL into pieces, removing page=# then gluing back together; but the problem is that the number could be 1 or more digits. Might there be a clean approach to this issue?

Thank you,



Now $page is 1.(based on your URL)

echo preg_replace('~page=\\d+&?~', '', 'list_ungraded_review_questions_students.php?page=1&chapter_name=Quadratic_Fun ctions§ion_name=multiplying_binomials_by_geometry');

Something like that? :slight_smile: