Reputation: 57
I have been developing a PHP page using Code Igniter. There is some function from controller:
public function language_testing($language_code, $logout=0)
{
echo ($language_code);
//come actions
}
And I'm trying to send the following url: http://mypage.com/index.php/controller/language_testing/bg#9
But my function shows me "bg" instead of "bg#9". Please, tell me, how can I get a content after "#"? I need it so much.
Upvotes: 1
Views: 143
Reputation: 3081
http://au.php.net/manual/en/function.parse-url.php
$urlComp=parse_url($yourURL);
echo $urlComp['fragment'];
Upvotes: 1
Reputation: 1160
The # is an HTML entity that is used in anchor tags to jump to a name reference. For example:
<a href="#test">Jump to test on page</a>
<a name="test">Test</a>
Thus, it is not being interpreted as part of your parameter. You should be able to use bg%23 as %23 is the escape character for hashing.
http://mypage.com/index.php/controller/language_testing/bg%239
How to escape hash character in URL
Upvotes: 0
Reputation: 2113
You need to alter the function params add one more parameter for code as well
public function language_testing($language, $code , $logout=0){
echo ($language);
echo ($code);
//come actions
}
and call it just like http://mypage.com/index.php/controller/language_testing/bg/9
it will resolve your problem and then you can concatenate both values
Upvotes: 0
Reputation: 1491
You can't. The #
is a HTML bookmark, used to redirect focus around a page using IDs on HTML elements. Browsers won't submit this as part of a URL to the server.
Depending on your rewrite rules, you'll either want to create a link that's semantically pleasing, like http://site.com/path/index.php/bg/9
or as http://site.com/path/index.php?bg=9
(which is what your rewrite rules would be achieving anyway).
Note if you really need the #
sign to be submitted for some reason then you'll need to submit it using %23
in the URL (@jth_92 beat me to it).
Upvotes: 0
Reputation: 59699
You should be posting to the following URL to get the value to appear in $logout
:
http://mypage.com/index.php/controller/language_testing/bg/9
Otherwise, the data after the pound sign isn't accessible by the server.
Upvotes: 1