Last active
December 11, 2015 01:49
-
-
Save srsbiz/4526564 to your computer and use it in GitHub Desktop.
Multibyte friendly tab to space replacer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Multibyte friendly tab replacer. | |
* @param string $line Line with tabs to convert | |
* @param int $tabsize Number of space characters in full width tab | |
* @return string Line without tabs | |
*/ | |
function tab2space($line, $tabsize = 4) | |
{ | |
while (($t = mb_strpos($line, "\t")) !== false) { | |
$preTab = $t ? mb_substr($line, 0, $t) : ''; | |
$line = $preTab . str_repeat(' ', $tabsize - (mb_strlen($preTab) % $tabsize)) . mb_substr($line, $t + 1); | |
} | |
return $line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment