1

Say I have a url like this in a php variable:

$url = "http://mywebsite.extension/names/level/etc/page/x";

how would I automatically remove everything after the .com (or other extension) and before /page/2?

Basically I would like every url that could be in $url to become http://mywebsite.extension/page/x

Is there a way to do this in php? :s

thanks for your help guys!

0

1 Answer 1

3

I think parse_url() is the function you're looking for. You can use it to break down an URL into it's component parts, and then put it back together however you want, adding in your own things as needed.

As PeeHaa noted, explode() will be useful for dividing up the path.

Sign up to request clarification or add additional context in comments.

3 Comments

how would I return only [path] in parse-url()? (the part I need to explode!). var xxx = $url[path] does not work. I'm bad at php sorry!
Tried this: $pagination = parse_url($url); $parts = explode('/', $pagination); $tag = end($parts); echo $tag; but it returns the entire url :(. Any ideas?
$pagination is an array. Try calling explode('/', $pagination["path"]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.