Autor Zpráva
Demeter
Profil *
Zdravím, mám kód, který mi vrací přeložený text, ale potřebuji z něj odstranit znaky jako je třeba \u000a\u000a..nebo jsem měl

blabla 'club' blabla
a vrátilo mi to
blabla \"klub\" blabla

$text = json_encode($_POST["text"]);
$text = urlencode($text);
$ch = curl_init("http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=doneCallback&appId=A0EE22ACDAE57377E5C0A39A6CF100010EEED155&from=cs&to=en&text=$text");
$getting = curl_exec($ch);
echo json_decode ($getting, 1);
Chro
Profil
Před 1. řádek vlož ještě
if (get_magic_quotes_gpc())
{
$text = stripslashes($_POST['text']);
}
Dále už v json_encode pracuj s $text.
Tori
Profil
Demeter:
Nepomohlo by nejdřív provést urlencode, a až potom json_encode?
Demeter
Profil *
takto

$text = urlencode($_POST['text']);
$text = stripslashes($text);
$text = json_encode($text);


mi to vrati jen

\
Davex
Profil
if (get_magic_quotes_gpc()) {
  $text = stripslashes($_POST['text']);
} else {
  $text = $_POST['text'];
}
$text = urlencode($text);

$ch = curl_init("http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=doneCallback&appId=A0EE22ACDAE57377E5C0A39A6CF100010EEED155&from=cs&to=en&text=$text");

// aby se vrácená data nevypsala, ale uložila do proměnné $getting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$getting = curl_exec($ch);

// výstupem funkce je pole a nikoliv řetězec
var_dump(json_decode($getting, 1));
Demeter
Profil *
to mi vraci

NULL

if (get_magic_quotes_gpc()) {
  $text = stripslashes($_POST['text']);
} else {
  $text = $_POST['text'];
}

$text = urlencode($text); 
$ch = curl_init("http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=doneCallback&appId=A0EE22ACDAE57377E5C0A39A6CF100010EEED155&from=en&to=cs&text=$text");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$getting = curl_exec($ch);
var_dump(json_decode($getting, 1));

curl_close($ch);
?>
Majkl578
Profil
Demeter:
Více snahy, méně lenosti. Stačí se podívat do manuálu a hned bys viděl: „NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit. “.
Prozkoumej obsah $getting, jestli je to validní JSON. Případně ti možná ještě pomůže json_last_error().
Demeter
Profil *
Hm, více snahy..dělal jsem to 3 hodiny, zkoušel i přes SOAP, ale i tak mi to nešlo, přes SOAP mi to vrátilo dokonce jen ten text v těch uvozovkách...např byl text

blabla 'neco' blabla..
tak mi to vypsalo jen
neco

vůbec netuším jak, nikdy jsem s tímto nedělal :/

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0