<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unix HOWTOs and Tips &#187; slug</title>
	<atom:link href="http://blog.bulsynt.org/tag/slug/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.bulsynt.org</link>
	<description>Short unix command line administration tips and scripts</description>
	<lastBuildDate>Wed, 30 Oct 2019 07:51:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple PHP cyr2lat command line transliteration filter from bulgarian to latin</title>
		<link>https://blog.bulsynt.org/2011/10/30/simple-php-cyr2lat-command-line-transliteration-filter-from-bulgarian-to-latin/</link>
		<comments>https://blog.bulsynt.org/2011/10/30/simple-php-cyr2lat-command-line-transliteration-filter-from-bulgarian-to-latin/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 12:04:55 +0000</pubDate>
		<dc:creator>Delyan Angelov</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[cyr2lat]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[romanization]]></category>
		<category><![CDATA[slug]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[transliteration]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://blog.bulsynt.org/?p=8</guid>
		<description><![CDATA[Sometimes you need to easily convert some Cyrillic Bulgarian text to its latin equivalent (a process known as "romanization", see Romanization of Bulgarian ). A possible use case scenario is making slugs for urls, containing bulgarian. Since it is a common task, in the best Unix tradition, it is very usefull to have a simple [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to easily convert some Cyrillic Bulgarian text to its latin equivalent (a process known as "<strong>romanization</strong>", see <a href="http://en.wikipedia.org/wiki/Romanization_of_Bulgarian"><strong>Romanization of Bulgarian</strong></a> ).</p>
<p>A possible use case scenario is making <strong>slugs</strong> for urls, containing bulgarian.</p>
<p>Since it is a common task, in the best Unix tradition, it is very usefull to have a <strong>simple command line filter</strong>, into which you can pipe the cyrillic text, and producing the romanized version in its output.</p>
<h2>Here is a simple version of the command line filter cyr2lat, written in php, that does just that:</h2>
<pre class="brush:php">#!/usr/bin/env php
&lt;?php
$cyr  = array('а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о','п','р',
              'с','т','у','ф','х','ц','ч','ш','щ','ъ','ь','ю','я',
              'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О','П','Р',
              'С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ь', 'Ю','Я' );
$lat = array( 'a','b','v','g','d','e','zh','z','i','y','k','l','m','n','o','p','r',
              's','t','u','f' ,'h' ,'ts' ,'ch','sh' ,'sht' ,'a' ,'y' ,'yu','ya',
              'A','B','V','G','D','E','Zh','Z','I','Y','K','L','M','N','O','P','R',
              'S','T','U','F' ,'H' ,'Ts' ,'Ch','Sh' ,'Sht' ,'A' ,'Y' ,'Yu' ,'Ya' );

$in = fopen ("php://stdin","r");
while($line = fgets($in)){
    echo str_replace($cyr, $lat, $line);
}</pre>
<hr />
<p><a title="Download the source of cyr2lat.php" href="http://blog.bulsynt.org/wp-content/uploads/2011/10/cyr2lat.php_.txt">Source of cyr2lat.php</a></p>
<p>To use it, just save it to a file named cyr2lat.php, then make this script executable by:</p>
<blockquote><p><strong>chmod 755 cyr2lat.php</strong></p></blockquote>
<p>... and possibly move it to a location in your path:</p>
<blockquote><p><strong>mv cyr2lat.php /usr/local/bin</strong></p></blockquote>
<p>or</p>
<blockquote><p><strong>mv cyr2lat.php ~/bin</strong></p></blockquote>
<p>After this, you can run for example:</p>
<blockquote><p><strong>echo "Това е текст на кирилица" | cyr2lat.php</strong></p></blockquote>
<p>and you will get:</p>
<blockquote><p>Tova e tekst na kirilitsa</p></blockquote>
<p>&nbsp;</p>
<p><strong>NB:</strong> This filter <strong>assumes that the input text is in the utf8 encoding</strong>. If you have an input text in the cp1251 encoding, just pipe it first through <strong>iconv</strong>, like this:</p>
<blockquote><p><strong>echo "Това е пак текст на кирилица, но този път с кодировка cp1251" |iconv -fcp1251 -tutf8 |cyr2lat.php</strong></p></blockquote>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.bulsynt.org/2011/10/30/simple-php-cyr2lat-command-line-transliteration-filter-from-bulgarian-to-latin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
