我遇到了一个问题,我翻译了Bing Translator API的一些内容。 文本还包含最多字符串中的HTML标签,我的问题是Bing在HTML标签之间添加了空白,所以我得到这样的文字:
Desculpe, nós não poderíamos encontrar um produto combinando sua solicitação de pesquisa. < br / >< forte > tente novamente? < / strong >
所以我的问题是:如何从HTML标签中删除空格? 我用php的preg_函数试了一下,但是我所做的并没有解决我的问题,希望对你有所帮助。
答案 0 :(得分:1)
如果只有一个空格'破坏'你的html,试试这样:
$text = str_replace(["< / ","< "], ["</", "<"], $text);
$text = str_replace([" / >", " >"], ["/>", ">"], $text);
但也许有一个更灵活的解决方案与正则表达式...