Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $re = '/<idx:entry.*?idx:orth value="([^"]+)">(.*?)<\/idx:entry>/m';
- $str=file_get_contents('book.html');
- $str=str_replace('<font size="3">en²','',$str);
- $str=str_replace('<font size="3">pl¹','',$str);
- $str=str_replace('<font size="3">pl³','',$str);
- $str=str_replace('<blockquote>','',$str);
- $str=str_replace('</blockquote>','',$str);
- $str=str_replace('<div height="0"></div> <div height="0"></div>','<br/>',$str);
- $str=str_replace('<div height="0"></div>','<br/>',$str);
- file_put_contents('book2.html',$str);
- preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
- $xml1='<?xml version="1.0" encoding="UTF-8" ?>
- <xdxf lang_from="ENG" lang_to="POL" format="visual">
- <meta_info>
- <title>Dictionary ENG-POL</title>
- <full_title>Dictionary ENG-POL</full_title>
- <description>Slownik angielsko polski</description>
- <file_ver>001</file_version>
- <creation_date>09-02-2020</creation_date>
- </meta_info>
- <lexicon>';
- $szab="<ar><k>%s</k><def>%s</def></ar>\n";
- $xml2='</lexicon>
- </xdxf>';
- $fp = fopen('slownik.xdxf', 'w');
- fwrite($fp, $xml1);
- foreach($matches as $m){
- $slowo=$m[1];
- $opis=$m[2];
- if(!empty($slowo) && !empty($opis)){
- $opis=str_replace('<br/>','__br__',$opis);
- $opis=str_replace('<b>','__b__',$opis);
- $opis=str_replace('</b>','__/b__',$opis);
- $opis=str_replace('<i>','__i__',$opis);
- $opis=str_replace('</i>','__/i__',$opis);
- $opis=str_replace('<h2>','__b__',$opis);
- $opis=str_replace('</h2>','__/b__',$opis);
- $opis=html_entity_decode(strip_tags($opis));
- $opis=htmlentities($opis,ENT_XML1);
- $opis=str_replace('__br__','<br/>',$opis);
- if(substr_count($opis,'__b__')==substr_count($opis,'__/b__')){
- $opis=str_replace('__b__','<b>',$opis);
- $opis=str_replace('__/b__','</b>',$opis);
- }
- if(substr_count($opis,'__i__')==substr_count($opis,'__/i__')){
- $opis=str_replace('__i__','<i>',$opis);
- $opis=str_replace('__/i__','</i>',$opis);
- }
- fwrite($fp, sprintf($szab,$slowo,$opis));
- }
- }
- fwrite($fp, $xml2);
- fclose($fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement