try to run below url :
http://seaway.fulba.com
search word :- Hello Hi
Chrome add special character %20 instead of space, I want keep word as it is (Hello Hi) in the url what ever is search there.
I am passing url using html5 pushstate function. Please help me to solve this issue.
Show ur your code or try urldecode() for this like,
$url=urldecode($yoururl);
echo $url;
And when passing your search string in pushstate use window.unescape or decodeURI()
That is not possible since space is an invalid character in a URL/I.
The ASCII hex code of the space character 20, therefore you see the encoded space as %20and an encoded ' as %27.
To reuse this in javascript you should use:
var str = decodeURI(URL_STRING);
In your case that would be:
var urlRValue = window.location.search.split('=')[1];
// "Hello%20Hi"
var str = decodeURI(urlRValue);
// "Hello Hi"
Related
I have a webapp created using C# and asp.net. I placed a parameter value in the querystring with a plus(+) sign. But the plus sign disappear.
How can I include the plus sign(+) in the query string without disappearing?
Please advise.
Thanks.
Edit: added code with UrlEncode
string str = Server.UrlEncode(Requery.QueryString["new"]);
+ sign has a semantic meaning in the query string. It is used to represent a space. Another character that has semantic importance in the query string is & which is used to separate the various var=value pairs in the query string.
Most server side scripts would decode the query parameters before using them, so that a + gets properly converted to a space. Now, if you want a literal + to be present in the query string, you need to specify %2B instead.
+ sign in the query string is URL-decoded to a space. %2B in the query string is URL-decoded to a + sign.
See the difference between
http://www.google.com/search?q=foo+bar
and
http://www.google.com/search?q=foo%2Bbar
In the above examples, Google's server script is URL-decoding the query parameters and then using them to do the search.
URL-encoding is nothing but % sign followed by the hex-code of the special character. For example, we know that the hex code of A is 0x41 (decimal: 65). Try this:
http://www.google.com/search?q=%41
Hope this makes URL-encoding clear.
So, if you want the + sign to be preserved when a JavaScript is fetching a URL with + signs in its query parameters and a server side script would process the query parameters after URL-decoding it, you should URL-encode the query parameters in the URL before using issuing the HTTP get request so that all + signs are converted to %2B's when the request reaches the server side script. Now when the server side script URL-decodes the query string, all %2B's gets converted back to + signs which is what you want.
See Encode URL in JavaScript? to learn how to URL-encode the parameters using JavaScript. Short answer from the discussion there:
var encodedURL = "http://example.com/foo.php?var=" + encodeURIComponent(param);
You should URLEncode your query string values to make sure any special characters are not lost.
Look at HTML URL Encoding Reference
You need to Encode the + sign - It's value should be %2B
I alter my previous statement so no one gets confused!
Create your url using the Server.UrlEncode.
e.g.
string myUrl = "http://myurl?param1=" + Server.UrlEncode("my+param+1");
For the solution, I have applied:
Step 1:Use Server.UrlEncode method for encoding the URL parameter.
Response.Redirect("YourURL?parameter=Server.UrlEncode(parameterValue.ToString().Trim()");
step 2: on another side, you get a string with a plus(+) sign.
var parameter = Request.QueryString["parameterValue"].ToString().Trim();
This is the result: %2beH8 --> +eH8
Other simple way is, Request.Url.ToString().Substring(Request.Url.ToString().IndexOf("=") + 1) assuming that my URL is, http://localhost/MyApp/Activate.aspx?ActivationCode=cHbtqH9P2dDZkx/mYUgFFo7nrNqSFgqdPisAzzu5/nwlEYDOHI+CQw==
before send you parameter, you need check if the parameter contains plus sign, if have you need replace to one flag, for example:
the parameter is: klasjdlkasd+djid3223
can you replace: klasjdlkasdFLAGdjid3223
and when you go convert, you need replace angain
klasjdlkasd+djid3223
Try this, it works for me:
Request.QueryString["new"].Trim();
The solution is to ALWAYS include .Replace(" ", "+") when you request querystring
string s = Request.QueryString["id"].Trim().Replace(" ", "+");
source: http://www.webmasterworld.com/forum47/3238.htm
Add this line in Decrypt Funcation:
strText = strText.Replace(" ", "+");
Trying to convert a plain URL text into a valid link.
The problem I have is that my link might contain both English (A-Z/a-z) and Hebrew (אבגדהוזחטיכךלמםנןסעפףצץקרשת) letters.
Using PHP's urlencode() function I was able to get the correct format for Hebrew, yet I cannot find the right way in which I convert it into a link.
My code so far (does not work with Hebrew letters):
$replyText = preg_replace('#(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)#', '$1', $replyText);
An example for a URL I need to convert into a link:
google.co.il%2F%D7%A9%D7%9C%D7%95%D7%9D_Hello.html
Will become:
google.co.il%2F%D7%A9%D7%9C%D7%95%D7%9D_Hello.html
Despite what I believe you have posted to represent the desired output, if this was my task, I think I would have a urlencoded href value in the <a> tag and human-readable link text.
Code: (Demo)
$replyText = "google.co.il%2F%D7%A9%D7%9C%D7%95%D7%9D_Hello.html";
echo '', urldecode($replyText), '';
Source Code Output:
google.co.il/שלום_Hello.html
Effective Output:
google.co.il/שלום_Hello.html
Notice that when you mouseover the link, your browser's status bar will show the un-encoded url anyhow.
You just need to replace %2F => /, so your link will be: google.co.il/%D7%A9%D7%9C%D7%95%D7%9D_Hello.html
link
I am using a JScript code like this:
shareLink = function (link) {
FB.ui({
method: 'share',
display: 'popup',
href: link,
}, function(response){});
}
and it is called in a line like this:
<?php
$sharedata = " ... parameters ... "
?>
<a href="javascript:shareLink('http://<?php echo $site; ?>/?v=<?php echo rawurlencode($sharelink); ?>');">
so, the destination script trasform parameter by using:
$str = rawurldecode($_GET["v"]);
the problem is when the url has a "+" character
using rawurlencode it its converted to "%2B"
zcu0xci%2FFMH2%2B7cLDPVP%2BgD7%2FwQJ%2FFT2Bw%3D%3D
but facebook change only "%2B" into "+" sign again:
zcu0xci%2FFMH2+7cLDPVP+gD7%2FwQJ%2FFT2Bw%3D%3D
and my script does not recognize it
EDIT:
if I echo the "v" parameter I get
zcu0xci/FMH2 7cLDPVP gD7/wQJ/FT2Bw==
instead of
zcu0xci/FMH2+7cLDPVP+gD7/wQJ/FT2Bw==
SOLUTION:
the solution I've found is to replace space by "+" before decode
$str = str_replace(" ","+",$str);
You don't need to use rawurldecode() on elements of the $_GET super-global variable. PHP decodes URL data for you.
In addition, you should generally use urlencode() to encode query string data. If you investigate the difference between these two functions, you'll see that urlencode() will translate any space character to the "+" character. This could possibly be the problem you're experiencing.
I'm having difficulty understanding the remainder of your question. You may need to work on your phrasing.
i have a javascript variable which contains a string with new lines and spaces e.g "a \n d" i want to pass this to php without losing any spaces or new lines. currently i am using this:
my_window = window.open("", "ChemEdit Molfile", "status=1,width=550,height=350");
urlString = "/chemedit/b.php?var=" +r;
my_window.location = urlString;
where r is the string i pass.
but if i do this in php
echo $_GET["var"];
i just get it on one line with the spaces gone
please help
You need to encode the string, you can use encodeURIcomponent() for that.
I am not sure but try using encodeURIComponent function:
my_window.location = encodeURIComponent(urlString);
if you're going to pass newline and spaces in an url,
you have to abide by the character rules of url strings,
in which spaces must be represented as '%20' and newlines
'\n" is '%5Cn'. the answers above will probably do this
automatically, but if you find you ever need to manually
encode or adjust, here is a reference for all special ascii
characters that should be converted for passing through
an http header request: http://www.w3schools.com/tags/ref_urlencode.asp
When a PHP site is requested like e.g. somesite.php?a=some text # some more
Currently it seems like $_REQUEST["a"] returns the string "some text ", how can I get "some text # some more". Are there other characters which get similar treatment by PHP?
The hash (#) is a "Fragment identifier" (also informally known as an "anchor") and refers to a location within the page - and you're right, it doesn't get sent to the server.
It's the only URL character that behaves like this.
If you need to include a hash character in a URL, you need to encode it as %23
somesite.php?a=<?=urlencode( "some text # some more" )?>
Turns it into:
somesite.php?a=some+text+%23+some+more
The "#" character is special in the URL specification; it refers to a location on the page (named by an 'a' tag like: <a name='top'>this is the top of the page</a>). It, and everything after it, is not passed to the server (php).
You can't. The browser doesn't send the part of the url after the # to the server.
So, it's not PHP that removes that part of the URL, it never sees it.
You can use urlencode() & urldecode() functions
it will be %23 instead of # symbol
If you have to have it, you can write javascript to re-post it for you:
<script>
function checkHash(){
var hash = window.location.hash;
if(hash){
// see if we've already included this
var loc = window.location.pathname;
if(!loc.indexOf('hashData=') >= 0){
// hashData param not included
window.location.href = loc + '&hashData=' + encodeURIComponent(hash) + hash;
}
}
};
checkHash();
</script>
There are some obvious issues with this (like it double-submits items). Note - if someone clicks on a hash link in the page, the code won't re-run, so you would need to monitor the hash for changes. You may or may not care about that case.
The # character, and any characters that follow it, specify and anchor.
This is a point within the page that the browser will scroll to.
As far as I know, this is for the browser's use only, and is never transmitted to the server side - presumably because it means nothing to the server,