cURL henter streng ned som har 1 til sidst
Jeg har oprettet 2 php filer:Fil et der bare skriver en json streng ud.
Fil 2 skal så hente min json streng og decode den.
Men problemet er når den henter url for den en streng der slutter med 1.
Når det decodes får jeg derfor bare et objekt som indeholder en int med værdi 1.
Hardcoder jeg strengen ind som side et giver mig i browser fungere det fint.
Nogen der har et bud?
Fil1:
$array = array("foo", "bar", "hallo", "world");
$myTweets = array(
"text" => "Just handed in my last project ever ".
"for my masters, all I have now is finals ".
"next week. Goodbye, school. Hello, life.",
"created_at" => "Thu May"
);
$myJSONTweets = json_encode($myTweets);
header("Content-type: text/plain");
print_r($myJSONTweets);
OUTPUT:{"text":"Just handed in my last project ever for my masters, all I have now is finals next week. Goodbye, school. Hello, life.","created_at":"Thu May"}
Fil2:
$ch = curl_init();
$URL = "http://mitdomaine.dk/wp-content/plugins/GetCategories.php";
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$resulta = curl_exec($ch);
curl_close($ch);
//$resulta = '{"text":"Just handed in my last project ever for my masters, all I have now is finals next week. Goodbye, school. Hello, life.","created_at":"Thu May"}';
//$resulta = str_replace("1", "", $resulta);
echo $resulta;
// giver output {"text":"Just handed in my last project ever for my masters, all I have now is finals next week. Goodbye, school. Hello, life.","created_at":"Thu May"}1
$json = $resulta;
$myJ = json_decode($resulta);
//echo $resulta;
echo "<hr><br/>";
var_dump( $myJ);
echo "<hr><br/>";
echo $myJ->text;