Last active
October 23, 2017 22:20
-
-
Save ribafs/d04e0b6d1a2fe373803567e8da7e997f to your computer and use it in GitHub Desktop.
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 | |
/* | |
Lê um arquivo texto/xml e grava uma aspa no início e uma aspa e vírgula ao final de cada linha. | |
Lê o arquivo tpl.xml e grava no arquivo tpl2.xml. | |
Crédito: makallio85 em https://stackoverflow.com/questions/21146528/php-write-to-file-at-end-of-each-line | |
Este arquivo foi criado para facilitar a criação de snippets no Visual Studio Code, pois como ele usa json para criar os | |
snippets então ele exige uma aspa no início e uma aspa com uma vrgula ao final de cada linha do snippets. | |
Assim eu abro inicialmente o código em um editor e procuro todas as " existentes e sobrescrevo com \". | |
Então eu uso este script para deixar redondo o body do snippet. | |
*/ | |
$list = preg_split('/\r\n|\r|\n/', file_get_contents ('tpl.xml')); | |
$contents = ''; | |
$ap='"'; | |
$apf='",'; | |
$nr=0; | |
foreach($list as $key => $item){ | |
$nr++; | |
if($nr < count($list)){ | |
if($nr < count($list)-1){ | |
$contents .= $ap.$item.$apf."\r\n"; | |
}else{ | |
$contents .= $ap.$item.$ap; | |
} | |
}else{ | |
$contents .= $item; | |
} | |
} | |
file_put_contents('tpl2.xml', $contents); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment