snipt

Ctrl+h for KB shortcuts

PHP

Encoding UTF8 and ISO-8859-1 Definitivo

1
2
3
4
5
6
7
public function encodeToUtf8($string) {
return mb_convert_encoding($string, “UTF-8″, mb_detect_encoding($string, “UTF-8, ISO-8859-1, ISO-8859-15″, true));
}

public function encodeToIso($string) {
return mb_convert_encoding($string, “ISO-8859-1″, mb_detect_encoding($string, “UTF-8, ISO-8859-1, ISO-8859-15″, true));
}
https://snipt.net/embed/089894772919c4a59206921f62424da5/
https://snipt.net/raw/089894772919c4a59206921f62424da5/
089894772919c4a59206921f62424da5
php
PHP
7
2016-09-27T12:36:08
True
False
False
/api/public/snipt/54476/
encoding-utf8-and-iso-8859-1
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">public function encodeToUtf8($string) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x">return mb_convert_encoding($string, “UTF-8″, mb_detect_encoding($string, “UTF-8, ISO-8859-1, ISO-8859-15″, true));</span> </span><span id="L-3"><a name="L-3"></a><span class="x">}</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="x">public function encodeToIso($string) {</span> </span><span id="L-6"><a name="L-6"></a><span class="x">return mb_convert_encoding($string, “ISO-8859-1″, mb_detect_encoding($string, “UTF-8, ISO-8859-1, ISO-8859-15″, true));</span> </span><span id="L-7"><a name="L-7"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
encoding, iso88591, php, uft8

Python

Converts a number to a character

1
2
3
4
5
6
7
8
def number2char(number):
    """ If you give the number one, it returns a, if you give 2, it returns b"""
    number = int(number)
    if number < 1 or number > 26:
        return False
    else:
        alphabet = map(chr, range(97, 123))
        return alphabet[number-1]
https://snipt.net/embed/430270a0a7c4721adb36a816a20873cb/
https://snipt.net/raw/430270a0a7c4721adb36a816a20873cb/
430270a0a7c4721adb36a816a20873cb
python
Python
8
2016-09-27T00:22:59
True
False
False
/api/public/snipt/27929/
converts-a-number-to-a-character
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">number2char</span><span class="p">(</span><span class="n">number</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="sd">&quot;&quot;&quot; If you give the number one, it returns a, if you give 2, it returns b&quot;&quot;&quot;</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">number</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">number</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">if</span> <span class="n">number</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">number</span> <span class="o">&gt;</span> <span class="mi">26</span><span class="p">:</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="bp">False</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">else</span><span class="p">:</span> </span><span id="L-7"><a name="L-7"></a> <span class="n">alphabet</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">chr</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">97</span><span class="p">,</span> <span class="mi">123</span><span class="p">))</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">return</span> <span class="n">alphabet</span><span class="p">[</span><span class="n">number</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> </span></pre></div> </td></tr></table>
cipher, encoding, python

Python

Convert a hexstring to an ASCII-String of optional XOR.

1
2
3
4
5
6
7
def hexstring2ascii(hexstring, xor=0):
    """ Convert a hexstring to an ASCII-String. If you like to XOR it, give the
        xor value as an integer. If not, leave it blank """
    ascii = ""
    for i in xrange(0, len(hexstring)/2):
        ascii = ascii + chr(int(hexstring[2*i:2*i+2],16)^xor) 
    return ascii
https://snipt.net/embed/db58bb40b5d5be5f5b56f8460f92054a/
https://snipt.net/raw/db58bb40b5d5be5f5b56f8460f92054a/
db58bb40b5d5be5f5b56f8460f92054a
python
Python
7
2016-09-27T00:23:06
True
False
False
/api/public/snipt/27926/
convert-a-hexstring-to-an-ascii-string-of-optional-xor
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">hexstring2ascii</span><span class="p">(</span><span class="n">hexstring</span><span class="p">,</span> <span class="n">xor</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="sd">&quot;&quot;&quot; Convert a hexstring to an ASCII-String. If you like to XOR it, give the</span> </span><span id="L-3"><a name="L-3"></a><span class="sd"> xor value as an integer. If not, leave it blank &quot;&quot;&quot;</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">ascii</span> <span class="o">=</span> <span class="s">&quot;&quot;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">hexstring</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">):</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">ascii</span> <span class="o">=</span> <span class="n">ascii</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">hexstring</span><span class="p">[</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="p">:</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">],</span><span class="mi">16</span><span class="p">)</span><span class="o">^</span><span class="n">xor</span><span class="p">)</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="n">ascii</span> </span></pre></div> </td></tr></table>
ascii, cipher, encoding, hex, python

MySQL

que encodign tiene mysql

SHOW VARIABLES LIKE "character\_set\_database";
https://snipt.net/embed/ae4f5f5e670b388b1da17f808180c5dd/
https://snipt.net/raw/ae4f5f5e670b388b1da17f808180c5dd/
ae4f5f5e670b388b1da17f808180c5dd
mysql
MySQL
1
2016-09-27T00:43:51
True
False
False
/api/public/snipt/13085/
que-encodign-tiene-mysql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">SHOW</span> <span class="n">VARIABLES</span> <span class="k">LIKE</span> <span class="s2">&quot;character\_set\_database&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
encoding, mysql, unicode, utf-8

Bash

convert text file from windows encoding to utf-8

iconv -f windows-1253 -t UTF-8 < old-file.txt > new-file.txt
https://snipt.net/embed/8cfb2460f7cd9f71844d99e6b84d24a1/
https://snipt.net/raw/8cfb2460f7cd9f71844d99e6b84d24a1/
8cfb2460f7cd9f71844d99e6b84d24a1
bash
Bash
1
2016-09-22T18:06:12
True
False
False
/api/public/snipt/1983/
convert-subtitles-from-windows-encoding-to-utf
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>iconv -f windows-1253 -t UTF-8 &lt; old-file.txt &gt; new-file.txt </span></pre></div> </td></tr></table>
conversion, encoding, files
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.