我目前在尝试让html实体显示双引号时遇到问题"
截至目前,它还没有产生它。
输出
<name>2nd Platoon "Viking" </name>
PHP代码
function GetPlayerID($id)
{
include('../../config/db.php');
$mysqliDebug = 1;
$sql = "SELECT * FROM players WHERE id=$id ORDER BY id ASC";
$results = mysqli_query($con, $sql);
if(!$results and $mysqliDebug) {
echo '<div style="margin-top:10px" class="alert alert-danger">There was an error in query:'. $results.'</div>';
echo $con->error;
}
while($row = mysqli_fetch_assoc($results))
{
return $row['playerid'];
}
}
$result = file_get_contents('../21st.json');
$json = json_decode($result,true);
$file = 'viking.xml';
$patch = 'viking.paa';
$str = '"Viking"';
$tags = $json['tags'];
$TOC = $json['tags']['1092531']['users'];
$RRDLead = $json['tags']['1656129']['users'];
$RRD = $json['tags']['1518730']['users'];
$GLead = $json['tags']['1217502']['users'];
$Guardian = $json['tags']['1217510']['users'];
$NLead = $json['tags']['1167334']['users'];
$Nightmare = $json['tags']['1065783']['users'];
$VLead = $json['tags']['1167327']['users'];
$Viking = $json['tags']['1065785']['users'];
$WLead = $json['tags']['1167327']['users'];
$Whiskey = $json['tags']['1065786']['users'];
$xml = new SimpleXMLElement('<!DOCTYPE squad SYSTEM "squad.dtd"><squad/>');
$xml->addAttribute('nick', '2nd');
$xml->addChild('name', '2nd Platoon '. htmlspecialchars("\"Viking\" "));
$xml->addChild('email','21stusarmyrangers@gmail.com');
$xml->addChild('web','http://21starmyrangers.enjin.com/viking');
$xml->addChild('picture', 'viking.paa');
$xml->addChild('title','2nd Platoon "Viking" / 21st Ranger Regiment');
$first = true;
foreach ( $Viking as $userId )
{
$user = isset($json['users'][$userId]) ? $json['users'][$userId] : null;
$tags = [];
if ($user)
{
$tags = array_filter($json['tags'], function($tag) use ($userId) {
return in_array($userId, $tag['users']);
});
}
// break;
$tagIds = array_keys($tags);
// echo htmlspecialchars(htmlspecialchars($user['username']));
foreach ( $tagIds as $tag )
{
$member = $xml->addChild('member');
if ($tag == 1065758)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'PV2 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065759)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'PFC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065760)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SPC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065762)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CPL ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065763)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SGT ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065764)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SSG ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065871)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SFC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065765)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'MSG ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065766)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', '1SG ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065767)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SGM ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065768)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'WO1 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065769)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW2 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065771)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW3 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065772)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW4 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065773)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW5 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065774)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', '2LT ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065776)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', '1LT ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1085054)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'MAJ ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1234581)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'LTC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
// break;
}
}
foreach ( $VLead as $userId )
{
$user = isset($json['users'][$userId]) ? $json['users'][$userId] : null;
$tags = [];
if ($user)
{
$tags = array_filter($json['tags'], function($tag) use ($userId) {
return in_array($userId, $tag['users']);
});
}
$tagIds = array_keys($tags);
// echo htmlspecialchars(htmlspecialchars($user['username']));
foreach ( $tagIds as $tag )
{
$member = $xml->addChild('member');
if ($tag == 1065758)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'PV2 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065759)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'PFC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065760)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SPC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065762)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CPL ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065763)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SGT ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065764)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SSG ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065871)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SFC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065765)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'MSG ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065766)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', '1SG ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065767)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'SGM ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065768)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'WO1 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065769)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW2 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065771)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW3 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065772)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW4 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065773)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'CW5 ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065774)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', '2LT ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1065776)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', '1LT ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1085054)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'MAJ ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
elseif ($tag == 1234581)
{
$member->addAttribute('id', GetPlayerID($userId));
$member->addAttribute('nick', 'LTC ' . htmlspecialchars($user['username']));
$member->addChild('name', htmlspecialchars($user['username']));
$member->addChild('email', 'N/A');
$member->addChild('icq', 'N/A');
$member->addChild('remark', 'N/A');
break;
}
break;
}
}
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->loadxml($xml->asXML());
$xpath = new DOMXPath($doc);
foreach( $xpath->query('//*[not(node())]') as $node ) {
$node->parentNode->removeChild($node);
}
// $doc->formatOutput = true;
Header('Content-type: text/html charset=UTF-8');
$doc->formatOutput = true;
$xmlString = $doc->saveXML();
echo $xmlString;
$doc->save($file);
JSON - https://gist.github.com/Ryahn/ac8fcc8ae77e9a6ee9138e268b592ed3
答案 0 :(得分:-1)
根据您的回复,这是您想要的吗?:
$string = "\" sdfsd\"";
echo htmlspecialchars(htmlentities($string));
输出:
" sdfsd"
编辑(关于chris85):
htmlspecialchars()
也可以替换为json_encode()
if&amp;正在出现