1 year ago

PHP How to create urls properly?

Posted 1 year ago by MartinZeltin

I have never understood how to create proper URLs. Every time I end up with trying to figure out if I should do ?var=value or &var=value and then if ?var=value already exists then I end up with ?var=value&var=value.

For example: I have pagination and my URL could look like this OR

Then my pagination link is href="?page=2" and I end up with

Then I want to navigate to the next page with href="?page=3" and I end up with this. Because it keeps on adding.

What a mess.... is there a function for PHP or Laravel that would create proper URLS? (knowing when to use ? or & and not add existing values all the time but replace them if they exist already.

Please sign in or create an account to participate in this conversation.