...">

Replacing an empty paragraph using preg_replace, space not recognized

I need to change this:

<p> </p>

In it:

<p class="notmobile"> </p>

in line. It seems simple, but the following does not 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'm not losing my mind, I replaced it with xxx to turn it into yyy, which worked perfectly. I think the problem is that my space is not normal space, as the content is probably the character set for Windows iso-8859-1 or whatever (or it got messy because we converted it to utf- 8 somewhere along the line ..)

Copying and pasting an empty paragraph from chome / firefox didn't work either.

I'm a little stuck :( Thanks for the help!

Update: here is base64_output, AwMD is the string from 0s that I used to mark the beginning of the string p, as mentioned above.

AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA8L3A + DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA + wqA8L3A + DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA + wqA8L3A + DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA + wqA8L3A + DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA + wqA8L3A + DQo8cD7CoDwvcD4NCjxwPsKgPC9wPg0KPHA + YmFzZTY0ZW5jb2Rpbmc8L3A + PC9w

* update2: charater ord php: 194, 160 - , . WEIRD. *

+5
4

UTF-8 11000010 10100000 NBSP \xA0. , :

= preg_replace('/<p>\p{Z}*<\/p>/u', '<p class="notmobile"> </p>', $f);
+5

<p> <p class="notmobile">?

$filecontent = str_replace("<p>", "<p class=\"notmobile\">", $filecontent);

<p> <p class="notmobile"> </p>?


, , :

$filecontent = str_replace("<p> </p>", "<p class=\"notmobile\"> </p>", $filecontent);
+1

&nbsp; ASCII- 0xA0, 160.

Try:

$filecontent  = preg_replace('/<p>\xA0<\/p>/', '<p class="notmobile"> </p>',   $filecontent);
+1
source
$filecontent  = preg_replace('/<p>\xC2\xA0<\/p>/', '<p class="notmobile"> </p>',    $filecontent);

It’s easy when you understand that nothing is as it seems! Modify useful answers now.

0
source

All Articles