我使用 SimpleXMLElement 生成 XML,其中一个子注释在其中得到了一个单引号的句子,然后接收器失败了……我怎样才能对句子进行编码以更改单引号。
代码:
$objLeadXML = new SimpleXMLElement ( '<CancelLead/>' );
$cancelReason = $objLead->getReasonForCancelling ();
$cancelReason = str_replace("\'", "'", $cancelReason);
$objLeadElement = $objLeadXML->addChild ( 'Lead', $cancelReason );
$objLeadElement->addAttribute ( 'ELMSRef', $objLead->getID () );
$objLeadElement->addAttribute ( 'CancelDate', $objLeadHistory->ActionDate );
$objLeadElement->addAttribute ( 'IsCancelled', $objLead->getStatusID () == KStatus::CANCELLED ? 1 : 0 );
$objLeadElement->addAttribute ( 'CancelledBy', $objLeadHistory->PerformedBy );
$cancelReason 包含取消原因,例如“没有驾照”,我需要对该句子中的单引号进行编码。