encoding

PHP urlencode - encode only the filename and dont touch the slashes

放肆的年华 提交于 2020-06-11 20:06:15
问题 http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip urlencode($myurl); The problem is that urlencode will also encode the slashes which makes the URL unusable. How can i encode just the last filename ? 回答1: Try this: $str = 'http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip'; $pos = strrpos($str, '/') + 1; $result = substr($str, 0, $pos) . urlencode(substr($str, $pos)); You're looking for the last occurrence of the slash sign. The part

Exporting Arabic Text from R

那年仲夏 提交于 2020-06-11 11:10:06
问题 I'm trying to export a data frame with Arabic text in R. When R imports Arabic text it converts it to UTF-8 codes. Like this: <U+0627><U+0644><U+0641><U+0631><U+0639> <U+0627><U+0644><U+062A><U+0634><U+0631><U+064A><U+0639><U+064A><U+060C> <U+0627><U+0644><U+0641><U+0631><U+0639> <U+0627><U+0644><U+062A><U+0646><U+0641><U+064A><U+0630><U+064A><U+060C><U+0627><U+0644><U+0641><U+0631><U+0639> <U+0627><U+0644><U+0642><U+0636><U+0627><U+0626><U+064A>. <U+0627><U+0644><U+062D><U+0643><U+0648><U

How to decode the unicode string starting with “%u” (percent symbol + u) in Python 3

╄→尐↘猪︶ㄣ 提交于 2020-06-01 05:15:14
问题 I get some HTML code like the following: <new>8003,%u767E%u5723%u5E97,113734,%u4E50%u4E8B%u542E%u6307%u7EA2%u70E7%u8089%u5473,6924743915824,%u7F50,104g,3,21.57,-2.16,0,%u4E50%u4E8B,1</new> I know I can find and replace all the "%u" with "/u" in Notepad++, and then paste it into Python console to let it display correctly in Chinese characters. But how can I do it automatically in Python? 回答1: Assuming that your input string contains "percent-u" encoded chracters, we can find and decode them

Arabic characters and UTF-8 in aria2

早过忘川 提交于 2020-05-30 08:42:49
问题 I use aria2 to have download with XML_RPC and when i want to have a download like this in php : $client->aria2_addUri( array($url), array("dir"=>'/home/amir/دانلود') ); it will create a folder named Ø´Ø³ÛØ¨ instead of دانلود. i post a related post in aria2 forums. and they said aria2 has not problem if that string sent to aria2 with utf-8. so, i used utf-8 header and convert the string to utf-8, but it's not works : header('Content-type:application/json; charset=utf-8'); $dir_on_server = mb

Python3 interpret unicode literal string as unicode character

怎甘沉沦 提交于 2020-05-30 03:31:25
问题 Now I have some unicode literal string like "\\u0061" which is by default interpreted as 6 unicode character. How can I convert it into unicode character 'a' ?. 回答1: Even easier: >>> "\\u0061".encode().decode('unicode-escape') 'a' >>> 回答2: You're looking for the unicode-escape codec: >>> import codecs >>> print(r'\u2603') \u2603 >>> print(codecs.decode(r'\u2603', 'unicode-escape')) ☃ 来源: https://stackoverflow.com/questions/52196916/python3-interpret-unicode-literal-string-as-unicode-character

Hex to String & String to Hex conversion in nodejs

て烟熏妆下的殇ゞ 提交于 2020-05-27 05:54:04
问题 I need to convert data into String to Hex and then again from Hex to String using nodejs 8 I have issue while decoding from Hex to String Code to convert string into hex function stringToHex(str) { const buf = Buffer.from(str, 'utf8'); return buf.toString('hex'); } Code to convert hex into string function hexToString(str) { const buf = new Buffer(str, 'hex'); return buf.toString('utf8'); } I have string dailyfile.host output of encoding :

Hex to String & String to Hex conversion in nodejs

旧时模样 提交于 2020-05-27 05:52:26
问题 I need to convert data into String to Hex and then again from Hex to String using nodejs 8 I have issue while decoding from Hex to String Code to convert string into hex function stringToHex(str) { const buf = Buffer.from(str, 'utf8'); return buf.toString('hex'); } Code to convert hex into string function hexToString(str) { const buf = new Buffer(str, 'hex'); return buf.toString('utf8'); } I have string dailyfile.host output of encoding :

Replacement for javascript escape?

馋奶兔 提交于 2020-05-26 11:44:18
问题 I know that the escape function has been deprecated and that you should use encodeURI or encodeURIComponent instead. However, the encodeUri and encodeUriComponent doesn't do the same thing as escape. I want to create a mailto link in javascript with Swedish åäö. Here are a comparison between escape, encodeURIComponent and encodeURI: console.log("mailto:?subject="+escape(subject)+"&body=" + escape(body)); console.log("mailto:?subject="+encodeURIComponent(subject)+"&body=" + encodeURIComponent

How to convert utf8 string to utf8 byte array?

﹥>﹥吖頭↗ 提交于 2020-05-25 05:48:06
问题 How can I convert string to utf8 byte array, I have this sample code: This works ok: StreamWriter file = new StreamWriter(file1, false, Encoding.UTF8); file.WriteLine(utf8string); file.Close(); This works wrong, file is in ASCII: byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(utf8string); FileStream fs = new FileStream(file2, FileMode.CreateNew); fs.Write(bytes, 0, bytes.Length); fs.Close(); I would like to get byte array what returned by this function: System.IO.File.ReadAllBytes(path

Migrating from sun.misc.BASE64 to Java 8 java.util.Base64

。_饼干妹妹 提交于 2020-05-24 17:11:06
问题 Question Are the Java 8 java.util.Base64 MIME Encoder and Decoder a drop-in replacement for the unsupported, internal Java API sun.misc.BASE64Encoder and sun.misc.BASE64Decoder ? What I think so far and why Based on my investigation and quick tests (see code below) it should be a drop-in replacement because sun.misc.BASE64Encoder based on its JavaDoc is a BASE64 Character encoder as specified in RFC1521 . This RFC is part of the MIME specification... java.util.Base64 based on its JavaDoc Uses