Si vous devez nettoyer des données mises en forme en rtf, en gros : RTF => TXT
Voici un script qui peut vous aider par contre vous devez installer unrtf sur votre serveur (testé sur ubuntu)
- Installation de unrtf :
sudo apt-get install unrtf
Ressources : http://www.gnu.org/software/unrtf/unrtf.html
- Le script :
/**
* Dans cette exemple le rtf est une chaine de caractere mais cela peut être un fichier text.
* Sources :http://www.gnu.org/software/unrtf/unrtf.html
*/
$str ='{\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fnil\fcharset0 MS Shell Dlg;}}{\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\f0\fs17 samples sent from Pronic Inc in Michigan to\par Main Factory in France\par FEDEX Invoice# 544425\par .\par \pard\f1\fs17 Payment Terms : \par - Deposit of 10% at reception of die design = 244.74 USD\par - Balance of 40% at delivery at the stamping facility (30 days net) = 911.59 USD\par - Balance of 5% after DDAP (60 days maximum after delivery i.e. maximum 02/5/2011) = 63.69 USD\par \pard - Balance of 5% after final customer approval (120 days maximum after delivery i.e. maximum 04/5/2011) = 63.69 USD\f0\fs17\par } ';
$rtfbuf = strtr($str, array("\r\n"=>"","\t"=>""));
file_put_contents("in", utf8_decode($str));
$last_line = system('unrtf -t text in > out', $retval);
$rtfbuf = file_get_contents("out");
$rtfbuf = explode(chr(10),$rtfbuf);
$rtftest=false;
if(count($rtfbuf)<>0){
foreach($rtfbuf as $v) {
if($rtftest) $rtfout[]= $v.chr(10);
elseif(trim($v) =="-----------------") $rtftest=true;
else continue;
}
}
print_r($rtfout);
30/08/2016 at 06:44
Thanks for sharing, this is a fantastic blog.Really thank you! Awesome.