简体   繁体   English

PHP | 通过Bing API翻译后,删除HTMLTag之间的空格

[英]PHP | Remove Blanks between HTMLTags after translating via Bing API

i got an Problem, i translating some stuff trought the Bing Translator API. 我遇到了问题,我翻译了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: 文本在最多的字符串中还包含HTML标签,我的问题是Bing在HTML标签之间添加了空格,因此我得到这样的文本:

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? 所以我的问题是:如何从HTML标签中删除空格? I tried it with php's preg_ functions, but nothing what i done solved my problem, hope for your help guys. 我用php的preg_函数进行了尝试,但是我所做的一切都解决不了我的问题,希望对您有所帮助。

If there are only single whitespaces 'corrupting' your html, try sth like this: 如果只有单个空格“破坏”了您的html,请尝试如下操作:

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

But maybe there is a more flexible solution with a regex... 但是也许正则表达式有一个更灵活的解决方案...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM