Okay guys.
So in this quick video we are going to fix the router.
Let me remind you what's the problem.
You are going to the main page.
It should accept the query parameters.
After you add a question mark.
Yet we have a not found page.
So I would say that this is actually a problem because this way with the current router, there is no
way we can pass some additional parameters to our pages.
If we would like to create something like before, we've made an example.
When we filtered the products, this wouldn't be possible.
That's why we just need to jump to the router and focus on that part on the normalize URI.
So let's see the problem.
Let me add any query parameters to a page and you can see it's instantly broken.
Though this is a perfectly fine method not only in PHP but generally in websites to pass some additional
parameters to a page.
This should be working and it should be displaying the main page same as slash contact with those query
parameters.
This should also be working and it's not.
And we're going to be using a Strtok function to fix this.
So first I'm going to call Strtok.
And then I'm going to explain that.
So we need the string and a token.
So we are passing the URI and the token is the question mark.
Now let me explain how this function works and why this is the best choice.
So this function will split this string into smaller chunks delimited by this delimiter, which in our
case we want it to be a question mark and it returns the string before the delimiter.
This is exactly what we want.
We want everything before the question mark and the reason why we use it is it is easier to use and
more efficient than other alternatives.
You probably also have seen me using a function called explode, which might seem similar.
We can also add a separator and convert a string into an array, but then we end up with an array,
so we need some additional handling in that case.
Also, if we are missing this question mark.
So if there are no parameters passed then this edge case is also handled fine.
Now if I would go to where are we on the contact page.
Let me jump to contact get route and if I would now like to var dump the get super global which should
contain all the query parameters.
I can see it is empty, but as soon as I come up with any query parameters like color equals red, I
have them available.
So that's everything we had to do to deal with this router limitation.
And by the way, we've learned a useful function.