PHP | Remove Blanks between HTMLTags after translating via Bing API

116 views Asked by At

i got an Problem, i translating some stuff trought the Bing Translator API. The Text also contains HTML Tags in the most strings, my problem is that Bing add Blanks between HTML Tags, so i get a text like this:

Desculpe, nós não poderíamos encontrar um produto combinando sua solicitação de pesquisa. < br / >< forte > tente novamente? < / strong >

So my Question is: How can i remove the Whitespaces from the HTML Tags? I tried it with php's preg_ functions, but nothing what i done solved my problem, hope for your help guys.

1

There are 1 answers

0
Rob On

If there are only single whitespaces 'corrupting' your html, try sth like this:

$text = str_replace(["< / ","< "], ["</", "<"], $text);
$text = str_replace([" / >", " >"], ["/>", ">"], $text);

But maybe there is a more flexible solution with a regex...