Php 从带有属性的HTML标记中删除空间

Php 从带有属性的HTML标记中删除空间,php,html,string,tags,space,Php,Html,String,Tags,Space,有没有写的方法 <b style="color:red">asd</b> asd b后面没有空格? 像这样 <bstyle="color:red">asd</b> asd 我想使用它作为字符串,没有空格,然后我想显示它,它应该作为html标记正常工作 我试过类似的东西 <b&nbsp;style="color:red">asd</b> asd 但它不起作用 这是字符串的一部分,我想在其中找到第100个空

有没有写的方法

<b style="color:red">asd</b>
asd
b后面没有空格? 像这样

<bstyle="color:red">asd</b>
asd
我想使用它作为字符串,没有空格,然后我想显示它,它应该作为html标记正常工作

我试过类似的东西

<b&nbsp;style="color:red">asd</b> 
asd
但它不起作用

这是字符串的一部分,我想在其中找到第100个空格,然后使用php分割字符串。如果我在标签的中间拆分它,就会产生问题

您可以使用css

<head>
<style type='text/css'>
b { color:red; }
</style>
</head>

//Other code

<b>abc</b>

b{颜色:红色;}
//其他代码
abc
另一个想法是在php代码中。你试过这么做吗

<?php
 $string = 'asdfasdfa<b style="color:red">asd</b> asdfasdf';
 $string2 = str_replace('<b style', '<bstyle', $string);
 //And then do the search
 $search = strpos($string2, " ", 0);
?>

完成该工作的唯一方法是在删除空格后对字符串使用,如下所示:

$str = str_replace('bstyle', 'b style', $str);
其中,
$str
是一个变量,包含从中删除空格的文本


否则,标记无效(可能会被浏览器忽略)。

为什么要这样做?这是较长文本的一部分,但我需要在30后找到空格。在那里我需要剪断绳子。。。它不应该在asd的中间,因为它会产生问题。我认为你不需要移除空间。真奇怪。我想你需要一个php函数。如果需要字符串中最后出现的空格,请使用
strrpos(“asdasdasd asdasd”,0)还有10个不同颜色的b标签。。。这么说,这件事已经结束了