or hash character is not passing in route parameters.
$this->post(’/postText/{data}’, function ($request, $response, $args) {
# code…
if($request->isPost()) {
echo $feed = $args[‘data’]; //My input is ’ Hello world #world ’. Output is only ‘Hello world’
}
});
Even here i have posted hash character but it is not visible on page why??
Without more info, that is the behavior I would expect. Can you post an example of the URL you are requesting and the route definition?
$this->post(’/postText/{data}’, function ($request, $response, $args) {
# code…
if($request->isPost()) {
echo $feed = $args[‘data’]; //My input is ’ Hello world #world ’. Output is only ‘Hello world’
}
});
tflight
November 5, 2017, 12:03pm
5
What does this give you?
$this->post(’/postText/{data}’, function ($request, $response, $args) {
$fragment = $request->getFragment();
echo $fragment;
});
still facing same problem
tflight
November 5, 2017, 12:53pm
7
I’m not sure I understand what you are trying to do. Browser’s don’t send the fragment (the part after the #).
Is there any solution of this problem??
I got this solution from stackoverflow and its working https://stackoverflow.com/questions/47123743/hash-is-not-passing-as-route-parameter-in-slim-framework-api
The # is a special character in the url spec, you can’t use it as input unless encoded.
From php use: urlencode() and urldecode()
From js use something like: encodeURIComponent()
That way you’ll get %23 instead of #, which will get stripped.
tflight
November 5, 2017, 4:35pm
10
That might work… you would likely need to use regex to match the route and need two parameters. But why not just use a different delimiter than #
? That would be much easier.
I am not using # as delimiter, I m passing # as input.
odan
November 6, 2017, 12:18pm
12
The main problem is that the browser won’t even send a request with a fragment part. The fragment part is resolved right there in the browser. So it’s reachable through JavaScript.