Im using the function get_query_var() to retrive my url path.
My url path looks like: /categories/500-Beställning
Now to retrieve this I use:
$url = get_query_var('title2');
If I var_dump($url); I get: string(29) "500-Best%C3%A4llning".
Now the letter ä is encoded. I have tried the function utf8_decode, which did not work, to decode it. But I am not quite sure to what is is encoded and how to correctly decode it. Thanks!
To decode URL encoded data, use urldecode:
<?php
$string = "500-Best%C3%A4llning";
print urldecode($string);
?>
Related
Here's the string:
%d0%91%d0%b5%d0%b7
I think it's cyrillic and I need it converted to something readable.
mb_detect_encoding() states it's ASCII.
When I do iconv('ASCII', 'UTF-8', $str), it shows me the same string.
Judging by this article, looks like it's in UTF-8, but how do I decode that into readable UTF?
Please help
UPDATE the following site was able to decode the text: http://2cyr.com/decode/?lang=en (thanks to Faiz Rasool for pointing out). The preset I used there is source=utf-8; postfilter=urlencoded, but I've no idea how to reproduce that on my server.
This string look like url encoded try this.
<?php
$str = "%d0%91%d0%b5%d0%b7";
echo utf8_encode(urldecode($str));
?>
I have been given some instructions to percent encode a URL twice. I know how to percent encode a URL once but how do you do it twice?
Surly when it is encoded once, it will be the same when encoded again.
Have I missed something?
Instructions or algorithm would be great!
It won't be the same since you encode the % used for encoding.
$url = 'http://www.youtube.com/watch?v=35_0IN36rUI'
echo $url;
echo urlencode($url);
echo urlencode(urlencode($url));
will give:
http://www.youtube.com/watch?v=35_0IN36rUI
http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D35_0IN36rUI
http%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253D35_0IN36rUI
To doubly encode the Url in php do:
$encodedUrl = urlencode(urlencode($url));
Definitely not the same output when encoded twice. The first adds percent encodings and the second will actually encode those percent signs... For example:
urlencode('guts & glory'); // "guts+%26+glory"
urlencode(urlencode('guts & glory')); // "guts%2B%2526%2Bglory"
So I am trying to encode/decode a url that when decoded will return the encoded + symbols from teh url. For example, I encodewebsite.com/index.php?eq=1+12 which when encoded turns the + into %2B, as it should. When I retrieve the value from $_REQUEST['eq'] and use urldecode() it echo's as "1 12". I cannot seem to get the decode to bring back the + so to speak. Am I doing something wrong here, or is there a more efficient/better way to go about doing this? Here is the exact encode/decode lines I use.
Submit Page
<?php
$eq = "1+12";
$send = '<a href="website.com/index.php?eq='.urlencode($eq).'</a>';
echo $send;
Retrieval page
<?php
$eq = urldecode($_REQUEST['eq']);
echo $eq;
?>
Don't run urldecode, the data in $_REQUEST is automatically decoded for you.
A plus sign, in a URL, is an encoded space. PHP decodes the hex value to a + automatically. Then, by running the result through urldecode, you are manually (and incorrectly) decoding the + to a .
Try using the function rawurldecode() instead of urldecode()
I encode it in JavaScript with encodeURIComponent() and decode it in PHP with rawurldecode() and it encodes/decodes properly for me, including the "+", but NOT with urldecode()
I need to get values in the url as it is
ex:
http://www.example.com/index?url=1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA==
but vriable url give me value of "1 LY2ePh1pjX4tjZ4 GS393Y2pjd16Cbq63T3tbfzMzd16CarA=="
Even though i have expected "1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA=="
any one can help me for this or know the reason
You see, you need to encode certain characters if you need to send them in a URL. For further references, I suggest you should read this Page. It seems that the URL you are getting isn't being encoded properly. If the URL is coming from your site, then I would suggest you to encode it properly.
In PHP, there is a function called urlencode, which may help you with this task.
A short explanation
URLs can only be sent over internet using ASCII character set.If you want to send characters which is outside this set, you need to encode it.URL encoding replaces unsafe ASCII characters with % followed by two hexadecimal digits corresponding to the character values in the ISO-8859-1 character-set.
The client sending the request apparently isn't URL encoding the value correctly. You can re-encode it after it's being decoded like this:
urlencode($_GET["url"])
IT convert %2B to space
The parameter you sent is wrong, it should have been encoded like so..
<?php
echo '<a href="http://www.example.com/index?url=', urlencode('1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA=='), '">';
?>
i have added encoding correctly now,It convert == correctly, but + sign encode to %2B correctly but in decode process it convert to space
As it seems that you’re having a Base-64 value there: You can use the URL safe alphabet for Base-64 that uses - and _ instead of + and / respectively:
$base64 = "1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA==";
// plain Base-64 to URL safe Base-64
$base64_safe = strtr($base64, '+/', '-_');
// URL safe Base-64 to plain Base-64
$base64 = strtr($base64_safe, '-_', '+/');
And if you know the length of the data, you can also omit the = padding:
rtrim($base64, '=')
How can I have PHP display this URL correctly?
Is there a working encoding method I can use that converts all of
253A%252F%252F
to
://
in
https%253A%252F%252Fvideos-private.s3.amazonaws.com%252Flesson05.flv
?
You should use double urldecode, i.e.,
$beuty_url = urldecode(urldecode("https%253A%252F%252Fbassrxprivate.s3.amazonaws.com%252Flesson05.flv"));
echo $beuty_url;
urldecode ;)
The urldecode function decodes any %## encoding in the given string.
In your "output" string you have %253A and so on.
Remove those %25 and everything will be fine.