SimpleXML PHP-保存<;br></br>;而不是&;书信电报;br&;燃气轮机&;lt/br&;燃气轮机;
我使用来更改文本节点的值,该节点也可能包含HTML 我面临的问题是,每当我保存一个值时,如:SimpleXML PHP-保存<;br></br>;而不是&;书信电报;br&;燃气轮机&;lt/br&;燃气轮机;,php,Php,我使用来更改文本节点的值,该节点也可能包含HTML 我面临的问题是,每当我保存一个值时,如: test<br></br> 为了编辑文本值,我使用以下代码: <?php $new_description = $_POST['description']; //get input text $xml_description = simplexml_load_file("path_to_file.xml") or die("
test<br></br>
为了编辑文本值,我使用以下代码:
<?php
$new_description = $_POST['description']; //get input text
$xml_description = simplexml_load_file("path_to_file.xml") or die("Error: Cannot create object");
$formatted_description = str_replace("<br />", "<br></br>", nl2br($new_description));
$xml_description->channel->item->description = html_entity_decode($formatted_description, null, 'utf-8');
$xml_description->asXML("path_to_file.xml");
?>
channel->item->description=html\u entity\u decode($formatted\u description,null,'utf-8');
$xml_description->asXML(“path_to_file.xml”);
?>
有没有办法避免编码,或者我应该更改库?您可以重新替换它们:
str_replace(
"<br></br>",
"<br></br>",
html_entity_decode($formatted_description, null, 'utf-8')
);
stru\u替换(
“br/br”,
“
”,
html_实体_解码($formatted_description,null,'utf-8'))
);
或者,如果您有很多需要忽略的内容,可以将它们分开:
$str = html_entity_decode($formatted_description, null, 'utf-8');
$to_reset = [
'<br>' => '<br>',
'</br>' => '</br>',
];
foreach($to_reset as $k => $v){
$str = str_replace(
$k,
$v,
html_entity_decode($str, null, 'utf-8')
);
}
$str=html\u entity\u decode($formatted\u description,null,'utf-8');
$to_重置=[
“br'=>”
”,
“/br'=>””,
];
foreach($to_重置为$k=>$v){
$str=str\u替换(
千美元,
$v,
html实体解码($str,null,'utf-8')
);
}
“也可以包含HTML的文本节点的值”-它要么是文本节点,要么包含HTML。如果test
应该是该节点的内容,则将其保存为XML中的testbr/br
是正确的。你有什么问题?请在你的问题中加入你想做的更详细的描述。另外,在问题和您想做的事情中添加“path_to_file.xml”的内容。基本上是添加一个。也许给出了使用CDATA的想法
$str = html_entity_decode($formatted_description, null, 'utf-8');
$to_reset = [
'<br>' => '<br>',
'</br>' => '</br>',
];
foreach($to_reset as $k => $v){
$str = str_replace(
$k,
$v,
html_entity_decode($str, null, 'utf-8')
);
}