我需要将其更改
<p> </p>
为:
<p class="notmobile"> </p>
在字符串上。看起来很简单,但以下方法不起作用:
$filecontent = preg_replace('/<p> <\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = preg_replace('/^<p> <\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = preg_replace('/<p>\s<\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = preg_replace('/<p>\s+<\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = str_replace('<p> </p>', '<p class="notmobile"> </p>', $filecontent);
为了确保我不会发疯,我对 xxx 进行了替换,将其转换为 yyy,效果很好。我认为问题是我的空间不是普通空间,因为内容可能是 Windows 字符集 iso-8859-1 或其他任何内容(或者它很混乱,因为我们已将其转换为utf-8 沿线某处..)
从 chome/firefox 复制并粘贴空段落也不起作用。
我有点卡住了:(感谢您的帮助!
更新:这是base64_output,AwMD是一串0,我用它来标记上面的p字符串的开头。 wPg0KPHA
+ wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L 3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+YmFzZTY0ZW5jb2Rpbmc8L3A+PC9w
*update2:我发现 php 中的字符 ord 值为:194 后跟 160 - 例如,它是两个字符*。
I need to change this:
<p> </p>
Into this:
<p class="notmobile"> </p>
on a string. Seems simple, but the following don't work:
$filecontent = preg_replace('/<p> <\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = preg_replace('/^<p> <\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = preg_replace('/<p>\s<\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = preg_replace('/<p>\s+<\/p>/', '<p class="notmobile"> </p>', $filecontent);
$filecontent = str_replace('<p> </p>', '<p class="notmobile"> </p>', $filecontent);
To make sure I wasn't going crazy, I did a replace on xxx to turn it into yyy which worked just fine. I think the problem is my space isn't a normal space as the content is probably that windows character set iso-8859-1 or whatever it is (or it's got confused because we've converted that to utf-8 somewhere along the line..)
Copying and pasting the empty paragraph from chome/firefox didn't work either.
I'm a bit stuck :( Thanks for helping!
Update: Here's the base64_output, AwMD is a string of 0s which I used to mark the beginning of a string of p's as above.
AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+wqA8L3A+DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA+YmFzZTY0ZW5jb2Rpbmc8L3A+PC9w
*update2: I've found the charater ord values in php are: 194 followed by 160 - eg it's two characters. WEIRD. *
发布评论
评论(4)
确实是 NBSP
\xA0
的 UTF-8 编码11000010 10100000
。如前所述,这是有效的:It's indeed the UTF-8 encoding
11000010 10100000
of NBSP\xA0
. As said earlier, this works:它可能是不间断空格
ASCII 代码
0xA0, 160
。尝试:
It might be a non-breaking space
ASCII code
0xA0, 160
.Try:
为什么不直接将
替换为
呢?
或者您是否尝试将所有对
标记(无论内容如何)替换为
?
对于中间只有 一个 空格的标签对,请尝试像这样替换它:
Why not just replace
<p>
with<p class="notmobile">
?Or are you trying to replace all pairs of
<p>
tags, regardless of content, with<p class="notmobile"> </p>
?For tag pairs with only one space in between, try replacing it like so:
当你意识到一切都不像看上去的那样时,就很容易了!现在修改有用的答案。
Easy when you realise nothing is as it seems! Modding up useful answers now.