SimpleXMLElement single quote encode
<p>I use SimpleXMLElement to generate XML and one of the child notes got a sentense in it that got a single quote, the receiver then fail... How can I encode the sentense to change the single quote.</p>

<p>Code:</p>

<pre><code>$objLeadXML = new SimpleXMLElement ( '&lt;CancelLead/&gt;' );

    $cancelReason = $objLead-&gt;getReasonForCancelling ();
    $cancelReason = str_replace("\'", "&amp;#39;", $cancelReason);

    $objLeadElement = $objLeadXML-&gt;addChild ( 'Lead', $cancelReason );
    $objLeadElement-&gt;addAttribute ( 'ELMSRef', $objLead-&gt;getID () );
    $objLeadElement-&gt;addAttribute ( 'CancelDate', $objLeadHistory-&gt;ActionDate );
    $objLeadElement-&gt;addAttribute ( 'IsCancelled', $objLead-&gt;getStatusID () == KStatus::CANCELLED ? 1 : 0 );
    $objLeadElement-&gt;addAttribute ( 'CancelledBy', $objLeadHistory-&gt;PerformedBy );
</code></pre>

<p>The $cancelReason contain a cancellation reason like "No Driver's License" I need to encode the single quote in that sentence.</p>
