admin管理员组文章数量:1403435
I'm passing a URL to a PHP file in which to change some colors etc. One of the colors is #ccc
and is passed up as &background=#ccc
which breaks my PHP file (It stops my $_GET
parameters at that hashtag, everything after that is not passed along)
I've tried encoding my url as encodeURIComponent(url)
which also encodes my ? and & I use for my $_GET string. When using encodeURI()
the hashtag isn't encoded at all.
Any ideas how to pass all my vars to my PHP file so I can read them there?
Please note that it's a stylesheet href. I can't/won't use jQuery's $.get()
method but just parse a tag and append it in my as such:
<link href="http://localhost:8888/test.php/layout.scss?primarycolor=hotpink&secondarycolor=white&background=#ccc&textcolor=black&linkcolor=black&font=Futura&" type="text/css" rel="stylesheet" id="custom-style">
I'm passing a URL to a PHP file in which to change some colors etc. One of the colors is #ccc
and is passed up as &background=#ccc
which breaks my PHP file (It stops my $_GET
parameters at that hashtag, everything after that is not passed along)
I've tried encoding my url as encodeURIComponent(url)
which also encodes my ? and & I use for my $_GET string. When using encodeURI()
the hashtag isn't encoded at all.
Any ideas how to pass all my vars to my PHP file so I can read them there?
Please note that it's a stylesheet href. I can't/won't use jQuery's $.get()
method but just parse a tag and append it in my as such:
<link href="http://localhost:8888/test.php/layout.scss?primarycolor=hotpink&secondarycolor=white&background=#ccc&textcolor=black&linkcolor=black&font=Futura&" type="text/css" rel="stylesheet" id="custom-style">
Share
Improve this question
asked Jul 10, 2015 at 9:03
CaptainCarlCaptainCarl
3,4896 gold badges41 silver badges74 bronze badges
5
- cant you just pass background=ccc and in code behind add hashtag? – Buzka91 Commented Jul 10, 2015 at 9:06
- yeah, use 'ccc' and provide hashtag afterwards. people always use too plicated solutions. – oshell Commented Jul 10, 2015 at 9:09
- 1 Except for the fact that people can pass "black" aswell. Which would convert to "#black" then. It would be a lot more plicated to outrule a lot of things that DON'T need a hashtag ;) – CaptainCarl Commented Jul 10, 2015 at 9:10
- hmmm.. but still they can pass background=#black so whats different? :) – Buzka91 Commented Jul 10, 2015 at 9:11
-
use
encodeURIComponent
which will convert#
to %23 but in your PHP you will get it as#
– Mr. A Commented Jul 10, 2015 at 9:13
3 Answers
Reset to default 5encodeURIComponent
is correct, but you only want to use it on the #ccc
bit. If you are doing it by hand (as in, hardcoding in the <link>
tag), then use %23
instead of #
.
Hash tags are not passed to the server, so that's why they're breaking your script. As for encoding, if encodeURIComponent() works, you'll probably have to encode each value in the URL. Alternatively, you can just replace the # symbol in your url with %23 using a simple string replace.
You could implement a proprietary encoding system. For example, saying that "#" is equal to "!-!" for example.
Then in your server-side PHP code you can run a str_replace("!-!", "#", $getVar)
statement to use the colour code correctly. Not ideal however.
Also, try: htmlentities
and html_entity_decode
: http://php/htmlentities
本文标签: phpEncoding javascript url to pass (hashtag)Stack Overflow
版权声明:本文标题:php - Encoding javascript url to pass #(hashtag) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744357722a2602388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论