php - <br /> must stay instead of \u003cbr / when using google translate -


i use function translate shown below. in text there many
tags , changed \u003cbr / after translation.

example: super preis - leistungsverhältnis.

das bekommen sie nur bei uns !

super prijs - . geld \u003cbr /\u003e u ons \u003cbr /\u003e

question: how can prevent text
tags not changed , stays after translations
tags.

function translate($text, $from = 'de', $to = 'nl'){  $texto_traducri = urlencode($text);  $query = "http://translate.google.nl/translate_a/t?client=t&text=$texto_traducri%0a%0a&hl=$from&sl=$from&tl=$to&multires=1&prev=enter&oc=5&ssel=3&tsel=6&sc=1";  $response = file_get_contents(     $query,     null,     stream_context_create(         array(             'http'=>array(             'method'=>"get",             'header'=>"referer: http://translate.google.nl/\r\n"             )         )     ) ); $p_separador = strpos($response,'","'); $p_separador = strpos($response,"]]"); $s_previo = substr($response,3,($p_separador)); $a_previo = explode("],[",$s_previo); $txt_sum = '';     foreach($a_previo $s_cadenaparcial){         $s_cadenaparcial = str_replace("]", "", $s_cadenaparcial);         $s_cadenaparcial = str_replace("[", "", $s_cadenaparcial);         $a_cadena = explode('","',$s_cadenaparcial);         $txt_sum.=substr($a_cadena[0],1);         }     $tagresult = $txt_sum;   

$tagresult = htmlspecialchars_decode($tagresult);

return $tagresult; } 

\u003c , \u003e represent unicode values < , >.

you convert them normal characters.

here example of how that:

<?     function uconverter($matches) {         return html_entity_decode('&#' . hexdec($matches[1]) . ';', ent_compat, 'utf-8');     }     function decode_uchars($str) {         return preg_replace_callback('/\\\\u([0-9a-fa-f]{4})/', uconverter, $str);     }       $in = 'super prijs - . geld \u003cbr /\u003e u ons \u003cbr /\u003e';     $out = decode_uchars($in); // super prijs - . geld <br /> u ons <br />      echo $out; ?> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -