Please help me convert this... I dont know how to call this kind of data, is it hex?
2%E6%9C%8819%E6%97%A5
I believe that this should be printed as 2月19日
How can I convert 2%E6%9C%8819%E6%97%A5 to be 2月19日 using PHP?
Thank You
That looks like it's URL encoded http://en.wikipedia.org/wiki/Url_encoding
PHP UrlDecode might do the trick.
http://www.php.net/manual/en/function.urldecode.php
There's an example at that link which shows url decoding the querystring of a page. I don't know PHP, but you might want soemthing like the following:
<?php
$original = "2%E6%9C%8819%E6%97%A5";
$decoded = urldecode($original);
echo $decoded;
?>
Related
I currently working on PHP and at some part of code I generate URL string. I set the GET parameter to currencyCode. But before I add &. So, at result I must get ¤cyCode but get ¤cyCode.
How do I fix it?
You need to create url this way using urlencode() function:
<?php
echo 'http://example.com/'.urlencode('¤cyCode');
I also think that your main problem is with displaying it. You should use:
echo htmlspecialchars('¤cyCode');
to display it.
Otherwise it seems browser change the first part of this string into: ¤ entity so you get something like that ¤cyCode and what makes you have display ¤ symbol what is ¤ and the rest of string cyCode
You should use urlencode() function in php to encode the url. Your code should look like this
<?php
echo 'http://yoursitename.com/'.urlencode('¤cyCode');
i need to remove () backslash in my string when using echo json_encode()?
my example..
$song_url = 116e9155e0afc11555cf33dc9c9bd25d.mp3
$resmsg[] = array("Song_name"=>"$song_name","Song_URL"=>"http://www.kbmusique.com/songs/$song_url");
echo json_encode($resmsg);
my output is
[{"Song_name":"djigh araouioui","Song_URL":"http:\/\/www.kbmusique.com\/songs\/116e9155e0afc11555cf33dc9c9bd25d.mp3"}]
but i need as
[{"Song_name":"djigh araouioui","Song_URL":"http://www.kbmusique.com/songs/116e9155e0afc11555cf33dc9c9bd25d.mp3"}]
Is there a way to solve this? Thank you.
Your comment indicates that you just need to get a copy/pastable URL for testing.
Just parse the JSON and extract the piece of data you need from it. i.e. If you want a text representation of something, then convert the JSON to text, don't try to hack the JSON into a specific form.
You could do this in PHP with json_decode, in a browser with JSON.parse(), or just use a tool such as the Chrome JSONView extension.
So i have url like that:
http://localhost/testproject/data/getData/幻想
And then in function getData i have that:
public function getData($title){
echo $title;
}
And in output i see:
%E5%B9%BB%E6%83%B3
Same is if i try $this->uri->segment(3).
Why is that so, and how to fix it? I also noticed that if i paste whole url here i get:
http://localhost/testproject/data/getData/%E5%B9%BB%E6%83%B3
I'm realy at dead end here...
Btw. file is encoded in UTF8.
Use this
site_url('data/getData/'.urlencode('幻想'));
On php end use this
$segment = $this->uri->segment(3);
$value = urldecode($segment);
See if this works for you.
you can use urldecode look at this http://php.net/manual/fr/function.urldecode.php
because of spacial characters, white spaces.
try encode or decode your url to see correct one you can user urldecode() function or urlencode() depends on the way you want to display...
http://www.php.net/manual/en/function.urlencode.php
http://php.net/manual/en/function.urldecode.php
I have been using URL decode on encoded URL variables from $_get.
The current problem I am facing is I have a URL encoded like this:
blah.php?url=http%3A%2F%2Fm.youtube.com%2F#/watch?feature=player_embedded&v=zd7c5tQCs1I&desktop_uri=%2Fwatch%3Fv%3Dzd7c5tQCs1I%26feature%3Dplayer_embedded
I'm not sure what kind of encoding this is, can someone help me? When I use just "urldecode" on this it just returns m.youtube.com
Edit: My problem is not that url decode isn't working, it works if I manually enter this encoded URL and use urldecode(), but when this encoded url is in the actual pages url and I use the _GET function then I try to decode it it stripes off everything after the "#" in the URL.
<?php print urldecode($_GET["url"]);?>
It returns
"http://m.youtube.com/"
instead of
"http://m.youtube.com/#/watch?feature=player_embedded&v=zd7c5tQCs1I&desktop_uri=/watch?v=zd7c5tQCs1I&feature=player_embedded"
I think the issue is that the pound sign is not encoded, if I refresh the page it strips away the pound sing and everything after it, so how do I get around this? Can I still retrieve the info from "GET" even though there is a pound sign? (#)
The problem is that the full link has multiple = signs, and browser cant determine, that the other = signs refer just to the url= parameter.
in your case, at first, you need to use function before link is given to url= parameter:
========================= 1) JAVASCRIPT ======================
<script type="text/javascript">
var mylink = encodeURIComponent('http://testest.com/link.php?name=sta&car=saab');
document.write("http://yoursite.com/url=" + mylink);
</script>
========================= 2)or PHP ===========================
<?php
$mylink = 'http://testest.com/link.php?name=sta&car=saab';
echo 'http://yoursite.com/url='.urlencode($mylink);
?>
so, your output (url parameter) will get like this
http://yoursite.com/url=http%3A%2F%2Ftest.com%2Flink.php%3Fname%3Dsta%
so, the url parameter will get the encoded url.
after that, your .php file needs to decode that "url" parameter-
<?php
$varr = $_GET['url'];
$varr = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($varr));
$varr = html_entity_decode($varr,null,'UTF-8');
echo $varr;
?>
that will give you the correct value
I read on php.net about urldecode function and they say that superglobal $_get is already decoded, ex: "The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results."
It is encoded into ASCII format .
see http://www.w3schools.com/tags/ref_urlencode.asp
So here is the problem, the pound sign (#) (Hash) wasn't encoded... since I can't go back and re-encode it I have to use javascript (ex. alert(window.location.hash);) to send me the full URL after the hash then I append it to PHP's version of the URL, I THEN use a find and replace function in PHP to replace the "#" with "%23", then I use the urldecode method and it returns the full proper url decoded.
This encoding is called percent encoding or URL encoding. You can use urldecode for decoding it. (Example: http://phpfiddle.org/lite/code/0nj-198 )
I've just been fiddling around with PHP, and I want to know if it's possible to do such a thing.
If so, can you please provide example code?
Update: What I mean, is I want to encode whatever file may be at the URI, not the URI itself. Sorry if I'm not clear.
You can put:
base64_encode(file_get_contents('http://www.google.com'));
I don't see why not...
<?php $file = file_get_contents("http://example.com/myfile.txt");
$encoded = base64_encode($file);
file_get_contents function will grab the HTML of given URL and base64_encode function will encode it.
<?php
$content = file_get_contents("http://google.com");
$encodedContent = base64_encode($content);
?>
You want to base64-encode a URL? Simple...
base64_encode($uri)