简体   繁体   中英

XML Non Breaking White Space

I think the cause of my woes at present is the non-breaking white space.

It appears some nasty characters have found their way into our MySQL database from our back office systems. So as I'm trying to run an XML output using PHP's XMLWriter, but there's loads of these silly characters getting into the field.

They're displayed in nano as ^K , in gedit as a weird square box , and when you delete them manually in MySQL they don't take up a phsyical space, despite that you know you've deleted something.

Please help me get rid of them!

Here is the line that is the nightmare at present (i've skipped out the rest of the XMLWriter buildup).

$writer->writeElement("description",$myitem->description);

After you have identified which character specifically you want to remove (and it's binary sequence), you can just remove it. For example with str_replace :

$binSequence = "..."; // the binary representation of the character in question
$descriptionFiltered = str_replace($binSequence, '', $myitem->description);
$writer->writeElement("description", $descriptionFiltered);

You have not specified yet about which concrete character you're talking, so I can't yet specify the binary sequence. Also if you're talking about a group of characters, the filtering might vary a bit.

Seems that they are vertical tabs , ASCII x0B. You should be able to REPLACE them in MySQL:

SELECT REPLACE('\v', '', `value`) WHERE key = 'foo';

However, the official reference doesn't mention \\v specifically. If it doesn't work, you can remove it afterwards in PHP with a simple str_replace (since PHP 5.2.5):

str_replace("\v", '', $result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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