This question already has answers here:
What is the equivalent of JavaScript's encodeURIcomponent in PHP?
(5 answers)
urlencode vs rawurlencode?
(11 answers)
Closed 4 years ago.
I save a web page edited by users in our app backend
in js : encodeURIComponent returns this
%3C!--%20saved%20from%20url%3D(0077)https%3A%2F%2Fwww.w3schools.com%2Fw3css%2Ftryw3css_templates_gourmet_catering.htm%23about
in php : urldecode returns this
<!-- saved from url=(0077)https:\/\/www.w3schools.com\/w3css\/tryw3css_templates_gourmet_catering.htm#about
so far so good....
now, when I fetch the data from the db and reencode it in php urlencode returns this :
%3C%21--+saved+from+url%3D%280077%29https%3A%2F%2Fwww.w3schools.com%2Fw3css%2Ftryw3css_templates_gourmet_catering.htm%23about
so it ends up in JS beeing decoded with + all over the place :
<!--+saved+from+url=(0077)https://www.w3schools.com/w3css/tryw3css_templates_gourmet_catering.htm#about
1 - yes I could just replace the + but I feel I am doing something wrong
2 - why does encodeurl do that if it is not compatible with js decodeURIcomponent ?
regards
Related
This question already has answers here:
PHP - Plus sign with GET query
(6 answers)
When should space be encoded to plus (+) or %20? [duplicate]
(5 answers)
Closed 3 years ago.
First of all thanks in advance to everyone helping me out with my question.
I've got a base64_encoded string that looks like:
$_GET['val']='8AH1Oc+gqwjMPyyAL+PIu2neFF5C+bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd+7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX+I+qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy+K9ABLBqUta9+0Mk3JCg+wO/WA2Bh06M0n4ux+qk=';
but when im trying to get the same variable to decode it i recieve it with pluses removed:
$string=$_GET['val'];
echo $string; // either echo $_GET['val']; output will be '8AH1Oc gqwjMPyyAL PIu2neFF5C bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd 7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX I qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy K9ABLBqUta9 0Mk3JCg wO/WA2Bh06M0n4ux qk='
Could somebody please explain why does it happen?
This question already has answers here:
Is it possible to preserve plus signs in PHP $_GET vars without encoding?
(7 answers)
Apache mod_rewrite %2B and plus (+) signs
(1 answer)
Closed 3 years ago.
How can I get the value from URL without replacing + sign with spaces?
URL: https://example.com/platform?id=xxtMEzBG56F3Z2Z+w1VT+g==
Currently, when I try to get variable in PHP by $_GET['id'] it automatically replaces + with space. How can I get the real value here?
The value I am getting is xxtMEzBG56F3Z2Z w1VT g==, what I want is xxtMEzBG56F3Z2Z+w1VT+g==
You can use $_SERVER with QUERY_STRING
echo str_replace('id=','',$_SERVER["QUERY_STRING"]);
This question already has answers here:
$_SERVER['REQUEST_URI'] with #hash too?
(2 answers)
Closed 6 years ago.
Request Path: http://localhost/1/2/# Example/
print_r($_SERVER['REQUEST_URI']);
Expected: /1/2/# Example/
Actual: /1/2/
Using urldecode doesn't have any effect because PHP is creating the array to begin with. Yes, this isn't an orthodox directory name though is there another way to determine the requested URI in PHP?
The # Parma is not send to the server!
This question already has answers here:
URL Decoding in PHP
(6 answers)
Closed 6 years ago.
I have problem decoding html encoded character using php, what should i do?
Below is the sample input.
%D8%A7%D8%AB%D8%A7%D8%B1%D9%87 %D8%A7%D9%84%D9%85%D8%B1%D9%87
Below is the sample output i want.
اثاره المره
Use PHP's urldecode function:
urldecode("%D8%A7%D8%AB%D8%A7%D8%B1%D9%87 %D8%A7%D9%84%D9%85%D8%B1%D9%87");
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Decoding numeric html entities via PHP
I have encoding error in the breadcrumbs (view file)
how can I fix that ? php or html ?
input => Madagascar 3: Europe's Most Wanted
output => Madagascar 3: Europe's Most Wanted
I'm using Yii PHP framework ans MySQL
You need to use this html_entity_decode
Here is a reference http://php.net/manual/en/function.html-entity-decode.php