Visualizzazione dei risultati da 1 a 2 su 2

Discussione: cURL ed echo HTML

  1. #1

    cURL ed echo HTML

    Salve a tutti vorrei sapere perchè dopo aver utilizzato cURL dentro una classe PHP,
    Apache decide di stampare anche i tag HTML senza interpretarli.
    Capita forse perchè cURL cambia il Content Type? Non credo si tratti di un problema di configurazione di Apache,
    perchè negli altri casi interpreta correttamente i tags HTML.
    La classe in questione è questa, essa viene inclusa tramite un require:

    codice:
    <?php
    require "JSON.php"; // A JSON encoder/decoder from http://pear.php.net
    
    class Metaweb {
      var $json;  // Holds the JSON encoder/decoder object
      var $URL = "http://api.freebase.com/api/service/mqlread";
    
      // Our constructor function sets up the JSON encoder/decoder
      function Metaweb() {
        // Set up our JSON encoder and decoder object
        $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
      }
      
      // This method submits a query and synchronously returns its result.
      function read($queryobj) {
        // Put the query into an envelope object
        $envelope = array("query" => $queryobj);
    
        // Serialize the envelope object to JSON text
        $serialized = $this->json->encode($envelope);
    
        // Then URL encode the serialized text
        $encoded = urlencode($serialized);
    
        // Now build the URL that represents the query
        $url = $this->URL . "?query=" . $encoded;
    	
        // Use the curl library to send the query and get response text
        $request = curl_init($url);
    
        // Return the result instead of printing it out.
        curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
    
        // Now fetch the URL
        $responsetext = curl_exec($request);
        curl_close($request);
    
        // Parse the server's response from JSON text into a PHP array
        $response = $this->json->decode($responsetext);
    
        // Return null if the query was not successful
        if ($response["code"] !== "/api/status/ok")
            return null;
    
        // Otherwise, return the query result from the envelope
        return $response["result"];
      }
    }
    ?>
    Se avete bisogno di ulteriori dettagli per potermi rispondere, fate sapere!
    Intanto grazie. Ciao!

  2. #2
    Ho aggiunto:

    codice:
    header('Content-type: text/html; charset=utf-8');
    ora sembra funzionare. Se avete soluzioni più eleganti son bene accette! Gracias.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.