PHP URL encoding method - php

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.

Related

How to send string(say: public_Key) having special characters in URL?

When I said simple string It works fine, but when I send my public_key string in the same way, It shows error.
I have tried the urlencode() method.
<iframe src="http://local.abc.com/formulaList?id=<?php echo $public_key; ?>" >
base64() doesn't work because its output can contain slashes (and anyway, most public key strings are already base64 encoded)
htmlspecialchars() escapes HTML special chars as its name implies which has nothing to do with urls (for example, é will be converted to é)
urlencode() is the right function to use but keep in mind an URL shouldn't be too long as explained in this SO answer
What problem did you encounter when using urlencode() ?
I write something this might work.
$url = htmlspecialchars("wdsd#ccddsd*");
header("Location: https://www.google.com?key={$url}");
this will work for you!

Convert french accent to specific encoding in PHP

In php, what function can I use to convert the text 'pétition' to 'p%E9tition'.
I have tried with uft8_encode and uft8_decode with no success.
%E9 is an URL encoded escape character. You can achieve this by urlecode($string).
If you want HTML escaping, you can either use htmlentities($string) (more encoding) or htmlspecialchars($string) (less encoding).
http://php.net/manual/en/function.urlencode.php
http://php.net/manual/en/function.htmlentities.php
http://php.net/manual/en/function.htmlspecialchars.php
When dealing with UTF-8 strings, you will need to decode the string (ie. with utf8_decode) before encoding with urlencode to be used in a query part of a URL.
print_r( urlencode(utf8_decode('pétition')) );
// p%E9tition
You can try to have a look at htmlentities.
This link can help

php urlencode encodes wrong?

If I try to encode the url
http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9
with urlencode() or http_build_query() it gives me the result
http%3A%2F%2Fherthabsc.de%2Findex.php%3Fid%3D3631%26%23038%3Btx_ttnews%5Btt_news%5D%3D13144%26%23038%3BcHash%3D9ef2e9ee006fb16188ebf764232a0ba9
But that's not what it should be. Is there a known bug? Or problems in use with wordpress?
You've double encoded the URL. Running urldecode() on your output string is giving me the following: http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9
EDIT:
try the following
urlencode(html_entity_decode('http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9'));

PHP: convert spaces in string into %20?

How can I convert spaces in string into %20?
Here is my attempt:
$str = "What happens here?";
echo urlencode($str);
The output is "What+happens+here%3F", so the spaces are not represented as %20.
What am I doing wrong?
Use the rawurlencode function instead.
The plus sign is the historic encoding for a space character in URL parameters, as documented in the help for the urlencode() function.
That same page contains the answer you need - use rawurlencode() instead to get RFC 3986 compatible encoding.
I believe that, if you need to use the %20 variant, you could perhaps use rawurlencode().

Removing the "%" encoding in URL string

I am attempting to open a page with window.open and it's not working. The path shown is like xyz/a%20b%20c%20.pdf, but it is supposed to be xyz/abc.pdf. If I remove the % and 20 manually, it works, how can I remove these characters using PHP?
Use urldecode:
(PHP 4, PHP 5)
urldecode — Decodes URL-encoded string
Description
string urldecode ( string $str )
Decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.
Example
echo urldecode('xyz/a%20b%20c%20.pdf');
This is known as URL Encoding. You need to decode the string. If you are using jQuery you should check out the URL Encode plug in.
You need to urldecode (as stated above).
However, you say that you can remove the %20 and it will work. I would say you need them, they decode to spaces. Check it out using this online url decoder:
http://www.convertstring.com/EncodeDecode/UrlDecode
it decodes to:
xyz/a b c .pdf
not
xyz/abc.pdf

Categories