Salve!
Sto cercando di creare uno script in PHP che mi elimini gli spazi vuoti sostituendoli con un : da un file ti testo..
per esempio:
il mio file e cosi composto:
123 abc def
1 2345 gh
lo script dovrebbe ritornare:
123:abc:def
1:2345:gh
dovrebbe leggere gli spazi vuoti ed eliminarli mettere un solo : tra le parole e quando incontra la fine della riga(\n) procede con la seconda riga..
ho creato questo code
$file_handle = fopen("filetotrim.txt", "r");
$text = ''; while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$text = replaceWhitespace($line_of_text, ':');
}
fclose($file_handle);
echo $text;
function replaceWhitespace($string, $replace) {
$string = preg_replace('/[\s]{1,}/', $replace, $string);
$string = substr($string, 0, strlen($string) - 1) . "\n";
return $string;
}
ma mi esce con questo errore:
Warning: feof(): supplied argument is not a valid stream resource in /home/atapi/Desktop/Programming/testtrim.php on line 7
Warning: fgets(): supplied argument is not a valid stream resource in /home/atapi/Desktop/Programming/testtrim.php on line 9
Qualcuno potrebbe darmi una mano??
Grazie