Username
Password
Remember me
Lost Password?
No account yet?
Register
Home
Articles
Web Design
Mixes
Images
Search
Programming
Operating Systems
Producing
DJing
Blog
Jokes
Programming menu
AJAX
Apple
Classic ASP
ASP.NET
CSS
HTML
Javascript
Joomla
Joomla Tutorial
PHP
SQL / mysql
VB / VB.NET
Links
Home
Articles
Programming
PHP Function to convert tabs to spaces
PHP Function to convert tabs to spaces
Tag it:
?
User Rating:
/ 1
Poor
Best
function tab2space($text, $spaces = 4) { // Explode the text into an array of single lines $lines = explode('\n', $text); // Loop through each line foreach ($lines as $line) { // Break out of the loop when there are no more tabs to replace while (false !== $tab_pos = strpos($line, '\t')) { // Break the string apart, insert spaces then concatenate $start = substr($line, 0, $tab_pos); $tab = str_repeat(' ', $spaces - $tab_pos % $spaces); $end = substr($line, $tab_pos + 1); $line = $start . $tab . $end; } $result[] = $line; } return implode('\n', $result); }
Comments
Search
Only registered users can write comments!
< Prev
Next >
[ Back ]