Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_string_between($string, $start, $end)
- {
- $string = " " . $string;
- $ini = strpos($string, $start);
- if ($ini == 0) return "";
- $ini+= strlen($start);
- $len = strpos($string, $end, $ini) - $ini;
- return substr($string, $ini, $len);
- }
- // Lê conteúdo do txt
- $documento = file_get_contents($arquivo);
- $linhas = explode("<ul", $documento);
- $novalinhas = "";
- $novoPostId = 100;
- $novaCategoria = "constituicao-da-republica-federativa-do-brasil-de-1988";
- $novoTituloCategoria = "CONSTITUIÇÃO DA REPÚBLICA FEDERATIVA DO BRASIL DE 1988";
- foreach($linhas as $novalinha)
- {
- $novoTitulo = "TÍTULO I";
- $novaData = date(DATE_RFC822);
- $novaData2 = date("Y-m-d h:i:s");
- $novoTituloSlug = get_string_between($novalinha, 'id="', '">');
- echo $novoTituloSlug;
- $novalinhas .= "<item>" . "\r\n";
- $novalinhas .= "<title>" . $novoTitulo . "</title>" . "\r\n";
- $novalinhas .= "<link>http://localhost/votanalei/" . $novoTituloSlug . "</link>" . "\r\n";
- $novalinhas .= "<pubDate>" . $novaData . "</pubDate>" . "\r\n";
- $novalinhas .= "<dc:creator><![CDATA[ale]]></dc:creator>" . "\r\n";
- $novalinhas .= "<guid isPermaLink='false'>http://localhost/votanalei/?p=" . $novoPostId . "</guid>" . "\r\n";
- $novalinhas .= "<description></description>" . "\r\n";
- $novalinhas .= "<content:encoded><![CDATA[<ul" . $novalinha . "]]></content:encoded>" . "\r\n";
- $novalinhas .= "<excerpt:encoded><![CDATA[]]></excerpt:encoded>" . "\r\n";
- $novalinhas .= "<wp:post_id>" . $novoPostId . "</wp:post_id>" . "\r\n";
- $novalinhas .= "<wp:post_date>" . $novaData2 . "</wp:post_date>" . "\r\n";
- $novalinhas .= "<wp:post_date_gmt>" . $novaData2 . "</wp:post_date_gmt>" . "\r\n";
- $novalinhas .= "<wp:comment_status>open</wp:comment_status>" . "\r\n";
- $novalinhas .= "<wp:ping_status>open</wp:ping_status>" . "\r\n";
- $novalinhas .= "<wp:post_name>" . $novoTituloSlug . "</wp:post_name>" . "\r\n";
- $novalinhas .= "<wp:status>publish</wp:status>" . "\r\n";
- $novalinhas .= "<wp:post_parent>0</wp:post_parent>" . "\r\n";
- $novalinhas .= "<wp:menu_order>0</wp:menu_order>" . "\r\n";
- $novalinhas .= "<wp:post_type>post</wp:post_type>" . "\r\n";
- $novalinhas .= "<wp:post_password></wp:post_password>" . "\r\n";
- $novalinhas .= "<wp:is_sticky>0</wp:is_sticky>" . "\r\n";
- $novalinhas .= "<category domain='category' nicename='" . $novaCategoria . "'><![CDATA[" . $novoTituloCategoria . "]]></category>" . "\r\n";
- $novalinhas .= "<category domain='post_tag' nicename='" . $novaCategoria . "'><![CDATA[" . $novoTituloCategoria . "]]></category>" . "\r\n";
- $novalinhas .= "<wp:postmeta>" . "\r\n";
- $novalinhas .= "<wp:meta_key>_edit_last</wp:meta_key>" . "\r\n";
- $novalinhas .= "<wp:meta_value><![CDATA[1]]></wp:meta_value>" . "\r\n";
- $novalinhas .= "</wp:postmeta>" . "\r\n";
- $novalinhas .= "</item>" . "\r\n";
- $novoPostId .= 5;
- }
- $file = fopen("test.txt", "w");
- $results = fwrite($file, $novalinhas);
- fclose($file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement