Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. function get_string_between($string, $start, $end)
  2. {
  3.     $string = " " . $string;
  4.     $ini = strpos($string, $start);
  5.     if ($ini == 0) return "";
  6.     $ini+= strlen($start);
  7.     $len = strpos($string, $end, $ini) - $ini;
  8.     return substr($string, $ini, $len);
  9. }
  10.  
  11. // Lê conteúdo do txt
  12. $documento = file_get_contents($arquivo);
  13. $linhas = explode("<ul", $documento);
  14. $novalinhas = "";
  15. $novoPostId = 100;
  16. $novaCategoria = "constituicao-da-republica-federativa-do-brasil-de-1988";
  17. $novoTituloCategoria = "CONSTITUIÇÃO DA REPÚBLICA FEDERATIVA DO BRASIL DE 1988";
  18.    
  19. foreach($linhas as $novalinha)
  20. {
  21.     $novoTitulo = "TÍTULO I";
  22.     $novaData = date(DATE_RFC822);
  23.     $novaData2 = date("Y-m-d h:i:s");
  24.     $novoTituloSlug = get_string_between($novalinha, 'id="', '">');
  25.     echo $novoTituloSlug;
  26.    
  27.     $novalinhas .= "<item>" . "\r\n";
  28.     $novalinhas .= "<title>" . $novoTitulo . "</title>" . "\r\n";
  29.     $novalinhas .= "<link>http://localhost/votanalei/" . $novoTituloSlug . "</link>" . "\r\n";
  30.     $novalinhas .= "<pubDate>" . $novaData . "</pubDate>" . "\r\n";
  31.     $novalinhas .= "<dc:creator><![CDATA[ale]]></dc:creator>" . "\r\n";
  32.     $novalinhas .= "<guid isPermaLink='false'>http://localhost/votanalei/?p=" . $novoPostId . "</guid>" . "\r\n";
  33.     $novalinhas .= "<description></description>" . "\r\n";
  34.     $novalinhas .= "<content:encoded><![CDATA[<ul" . $novalinha . "]]></content:encoded>" . "\r\n";
  35.     $novalinhas .= "<excerpt:encoded><![CDATA[]]></excerpt:encoded>" . "\r\n";
  36.     $novalinhas .= "<wp:post_id>" . $novoPostId . "</wp:post_id>" . "\r\n";
  37.     $novalinhas .= "<wp:post_date>" . $novaData2 . "</wp:post_date>" . "\r\n";
  38.     $novalinhas .= "<wp:post_date_gmt>" . $novaData2 . "</wp:post_date_gmt>" . "\r\n";
  39.     $novalinhas .= "<wp:comment_status>open</wp:comment_status>" . "\r\n";
  40.     $novalinhas .= "<wp:ping_status>open</wp:ping_status>" . "\r\n";
  41.     $novalinhas .= "<wp:post_name>" . $novoTituloSlug . "</wp:post_name>" . "\r\n";
  42.     $novalinhas .= "<wp:status>publish</wp:status>" . "\r\n";
  43.     $novalinhas .= "<wp:post_parent>0</wp:post_parent>" . "\r\n";
  44.     $novalinhas .= "<wp:menu_order>0</wp:menu_order>" . "\r\n";
  45.     $novalinhas .= "<wp:post_type>post</wp:post_type>" . "\r\n";
  46.     $novalinhas .= "<wp:post_password></wp:post_password>" . "\r\n";
  47.     $novalinhas .= "<wp:is_sticky>0</wp:is_sticky>" . "\r\n";
  48.     $novalinhas .= "<category domain='category' nicename='" . $novaCategoria . "'><![CDATA[" . $novoTituloCategoria . "]]></category>" . "\r\n";
  49.     $novalinhas .= "<category domain='post_tag' nicename='" . $novaCategoria . "'><![CDATA[" . $novoTituloCategoria . "]]></category>" . "\r\n";
  50.     $novalinhas .= "<wp:postmeta>" . "\r\n";
  51.     $novalinhas .= "<wp:meta_key>_edit_last</wp:meta_key>" . "\r\n";
  52.     $novalinhas .= "<wp:meta_value><![CDATA[1]]></wp:meta_value>" . "\r\n";
  53.     $novalinhas .= "</wp:postmeta>" . "\r\n";
  54.     $novalinhas .= "</item>" . "\r\n";
  55.     $novoPostId .= 5;
  56. }
  57.  
  58. $file = fopen("test.txt", "w");
  59. $results = fwrite($file, $novalinhas);
  60. fclose($file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement