Pound sign (#) not working in PHP

2019-01-20 06:21发布

I have variable 'cno' and it's values sometimes have 123# - ( end with pound sign. )

The problem is, after passing the URL I couldn't get variable with pound sign.

ex: my url - /index.php?cno=34#

So I need to get $_GET['cno'] value like = 34#, but it only display 34

Is it possible to get 'cno' variable value with pound sign.

thanks.

标签: php get
2条回答
我命由我不由天
2楼-- · 2019-01-20 06:38

You'll have to encode the # as %23, so your URL would look like this:

/index.php?cno=34%23

To make it easier use PHP's built-in urlencode function: http://php.net/urlencode

$cno = "34#";
$url = urlencode("/index.php?cno=" . $cno); // "/index.php?cno=34%23"
查看更多
乱世女痞
3楼-- · 2019-01-20 06:49

# in a URL indicates a document fragment. URL-encode your values before sending them.

查看更多
登录 后发表回答