Ir para conteúdo
Fórum Script Brasil
  • 0

Gerando TXT com HTML


Caio Guimos

Pergunta

Olá pessoal! Tu legal?

Estou com um probleminha aqui, que não me possibilita gerar nem escrever em um arquivo TXT, o código abaixo.

O código é referente ao feed do Facebook. Ele até me imprime o feed, mas ao adicionar o "fopen", "fwrite" e "fclose", ele cria o arquivo em branco e não o escreve.

Estou tentando fazer com que o foreach fosse exportado para um txt ao invés de somente imprimir com o echo.

Agradeço desde já à todos pela atenção e pela força.

Segue abaixo o fonte.

<?php
//function to retrieve posts from facebook server
function loadFB($fbID){
	//facebook feed url
    $url="http://www.facebook.com/feeds/page.php?id=".$fbID."&format=atom10";
    
    //load and setup CURL
    $c = curl_init();
    
    //set options and make it up to look like firefox
	$userAgent = "Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";
	curl_setopt($c, CURLOPT_USERAGENT, $userAgent);
	curl_setopt($c, CURLOPT_URL,$url);
	curl_setopt($c, CURLOPT_FAILONERROR, true);
	curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($c, CURLOPT_AUTOREFERER, true);
	curl_setopt($c, CURLOPT_RETURNTRANSFER,true);
	curl_setopt($c, CURLOPT_VERBOSE, false);     
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    
    //get data from facebook and decode XML
    $page = curl_exec($c);
    $pxml= new SimpleXMLElement($page);

    //close the connection
    curl_close($c);
     
    //return the data as an object
    return $pxml->entry;
}

//BE SURE to enter your facebook id here
$fbid="28956907120";

//how may posts to show
$fbLimit=10;
//variable used to count how many weÕve loaded
$fbCount=0;

//call the function and get the posts from facebook
$myPosts=loadFB($fbid);

//set timezone (change this to your timezone)
date_default_timezone_set("Brazil/East");
	
  
   
//loop through all the posts we got from facebook
foreach($myPosts as $dPost){
      //get the post date / time and convert to unix time
      $dTime = strtotime($dPost->published);
      //format the date / time into something human readable
      //if you want it formatted differently look up the php date function
      $myTime=date("M d Y h:ia",$dTime);
      //output the date / time
      echo("<br />".$myTime."<br />");
      //output the message body
      echo($dPost->content);
      //increment counter
      $fbCount++;
      //if we've outputted the number set above in fblimit we're done
      if($fbCount >= $fbLimit) break;    
}

?>

Eu coloco o código abaixo, porém ele não escreve no arquivo, só o cria.

 $file = fopen('cache.txt', 'w');
         fwrite($file, $myPosts); 
         fclose($file);
Editado por Caio Guimos
Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...