Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

UTF8 Para bancos mysql

1
2
3
4
5
6
7
8
<?php    		

mysql_query( "SET NAMES 'utf8'" );
mysql_query( 'SET character_set_connection=utf8' );
mysql_query( 'SET character_set_client=utf8' );
mysql_query( 'SET character_set_results=utf8' );

?>
https://snipt.net/embed/1da4a52dd9ebbce965c02bd7b983b315/
https://snipt.net/raw/1da4a52dd9ebbce965c02bd7b983b315/
1da4a52dd9ebbce965c02bd7b983b315
php
PHP
8
2016-12-04T00:55:40
True
False
False
Jul 11, 2012 at 08:59 AM
/api/public/snipt/43764/
utf8-para-bancos-mysql
<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></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nb">mysql_query</span><span class="p">(</span> <span class="s2">&quot;SET NAMES &#39;utf8&#39;&quot;</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nb">mysql_query</span><span class="p">(</span> <span class="s1">&#39;SET character_set_connection=utf8&#39;</span> <span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nb">mysql_query</span><span class="p">(</span> <span class="s1">&#39;SET character_set_client=utf8&#39;</span> <span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="nb">mysql_query</span><span class="p">(</span> <span class="s1">&#39;SET character_set_results=utf8&#39;</span> <span class="p">);</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
charset, sql, utf8

MySQL

Find MySQL Collation and Charsets

1
2
3
4
USE database_name;

SHOW VARIABLES LIKE "character_set_database";
SHOW VARIABLES LIKE "collation_database";
https://snipt.net/embed/fdaa71b9921a6e4991919d5e578a1791/
https://snipt.net/raw/fdaa71b9921a6e4991919d5e578a1791/
fdaa71b9921a6e4991919d5e578a1791
mysql
MySQL
4
2016-12-04T00:56:59
True
False
False
/api/public/snipt/41726/
find-mysql-collation-and-charsets
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">USE</span> <span class="n">database_name</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></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><span id="L-4"><a name="L-4"></a><span class="k">SHOW</span> <span class="n">VARIABLES</span> <span class="k">LIKE</span> <span class="s2">&quot;collation_database&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
charset, collation, mysql, utf8

PHP

Utf email send function

1
2
3
4
5
function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
  $header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
  mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}
 
https://snipt.net/embed/0f4f28352ddb605fb632dc0a50719b3c/
https://snipt.net/raw/0f4f28352ddb605fb632dc0a50719b3c/
0f4f28352ddb605fb632dc0a50719b3c
php
PHP
5
2016-12-05T09:13:56
True
False
False
/api/public/snipt/38190/
utf-email-send-function
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">function mail_utf8($to, $subject = &#39;(No subject)&#39;, $message = &#39;&#39;, $header = &#39;&#39;) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> $header_ = &#39;MIME-Version: 1.0&#39; . &quot;\r\n&quot; . &#39;Content-type: text/plain; charset=UTF-8&#39; . &quot;\r\n&quot;;</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> mail($to, &#39;=?UTF-8?B?&#39;.base64_encode($subject).&#39;?=&#39;, $message, $header_ . $header);</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> </span> </span></pre></div> </td></tr></table>
email, send, unicode, utf8

PHP

accented char replacer

1
2
3
4
5
<?php
function rmAccent($string){
    return preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8'));
}
?>
https://snipt.net/embed/516942114dc9d831156cc1c808eb8e2c/
https://snipt.net/raw/516942114dc9d831156cc1c808eb8e2c/
516942114dc9d831156cc1c808eb8e2c
php
PHP
5
2016-12-02T13:30:14
True
False
False
/api/public/snipt/34775/
accented-char-replacer
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">rmAccent</span><span class="p">(</span><span class="nv">$string</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nb">preg_replace</span><span class="p">(</span><span class="s1">&#39;~&amp;([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i&#39;</span><span class="p">,</span> <span class="s1">&#39;$1&#39;</span><span class="p">,</span> <span class="nb">htmlentities</span><span class="p">(</span><span class="nv">$string</span><span class="p">,</span> <span class="nx">ENT_QUOTES</span><span class="p">,</span> <span class="s1">&#39;UTF-8&#39;</span><span class="p">));</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"special char", accent, php, remove, special, url, utf8

Bash

Recursively replace BOM-Characters in files

find . -type f -exec sed -i '1 s/^\xef\xbb\xbf//' {} +
https://snipt.net/embed/7b23948a6d67efbc9c7475550756078d/
https://snipt.net/raw/7b23948a6d67efbc9c7475550756078d/
7b23948a6d67efbc9c7475550756078d
bash
Bash
1
2016-12-04T18:54:58
True
False
False
/api/public/snipt/30472/
recursively-replace-bom-characters-in-files
<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></span><span id="L-1"><a name="L-1"></a>find . -type f -exec sed -i <span class="s1">&#39;1 s/^\xef\xbb\xbf//&#39;</span> <span class="o">{}</span> + </span></pre></div> </td></tr></table>
bom, recursively, replace, sed, shell, utf8

MySQL

set mysql to utf8

1
2
3
4
SET NAMES utf8;
SET character_set_connection=utf8;
SET character_set_client=utf8;
SET character_set_results=utf8;
https://snipt.net/embed/3536e50e6fd630fe9a100b79fee09560/
https://snipt.net/raw/3536e50e6fd630fe9a100b79fee09560/
3536e50e6fd630fe9a100b79fee09560
mysql
MySQL
4
2016-12-04T15:10:56
True
False
False
/api/public/snipt/29323/
set-mysql-to-utf8
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kt">SET</span> <span class="n">NAMES</span> <span class="n">utf8</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a><span class="kt">SET</span> <span class="n">character_set_connection</span><span class="o">=</span><span class="n">utf8</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="kt">SET</span> <span class="n">character_set_client</span><span class="o">=</span><span class="n">utf8</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="kt">SET</span> <span class="n">character_set_results</span><span class="o">=</span><span class="n">utf8</span><span class="p">;</span> </span></pre></div> </td></tr></table>
mysql, utf8

SQL

convert charset of all mysql tables for specific db

1
2
3
SELECT
  CONCAT('ALTER TABLE ', table_name, ' CONVERT TO CHARACTER SET utf8;')
  FROM tables WHERE TABLE_SCHEMA='my_bad_db' AND TABLE_COLLATION LIKE '%latin1%';
https://snipt.net/embed/0dfd7d04749ad3da5b1d401d4f538995/
https://snipt.net/raw/0dfd7d04749ad3da5b1d401d4f538995/
0dfd7d04749ad3da5b1d401d4f538995
sql
SQL
4
2016-12-04T02:48:39
True
False
False
/api/public/snipt/8329/
convert-charset-of-all-mysql-tables-for-specific-db
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">SELECT</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">CONCAT</span><span class="p">(</span><span class="s1">&#39;ALTER TABLE &#39;</span><span class="p">,</span> <span class="k">table_name</span><span class="p">,</span> <span class="s1">&#39; CONVERT TO CHARACTER SET utf8;&#39;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">FROM</span> <span class="n">tables</span> <span class="k">WHERE</span> <span class="n">TABLE_SCHEMA</span><span class="o">=</span><span class="s1">&#39;my_bad_db&#39;</span> <span class="k">AND</span> <span class="n">TABLE_COLLATION</span> <span class="k">LIKE</span> <span class="s1">&#39;%latin1%&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
convert, mysql, utf8
Copyrighted, illegal, or inappropriate content? Email [email protected].