Paul Konstanski
asked on
XML Type Format Inclusion of Font Attributes
When I initially posed this question here: question here, I was given this suggested code that I thought worked fine.
But upon closer inspection, the code in the third line that begins with <bod> cuts off when it encounters the <em>. The output looks like this:
obj->ttl = This is the Title
obj->sub = This is a sub-title
obj->bod = This is a body with
obj->con = This creates a continue button
I need some help in how to fix this. ]
The third line should look like this:
obj->bod = This is a body with <em>Italics in the middle</em>
Thanks.
<?php // /demo/temp_pkonstan2.php
/**
* Some XML-related ideas
* See: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28668382.html
*/
error_reporting(E_ALL);
// A MALFORMED XML DOCUMENT FROM THE QUESTION AT EE
$xml = <<<EOD
<ttl>This is the Title</ttl>
<sub>This is a sub-title</sub>
<bod>This is a body with <em>Italics in the middle</em></bod>
<con>This creates a continue button</con>
EOD;
// CORRECT THE FORMATION OF THE XML
$xml = '<wrap>' . $xml . '</wrap>';
// TRY TO MAKE AN OBJECT
$obj = SimpleXML_Load_String($xml);
// SHOW THE PROPERTIES OF THE OBJECT
echo '<pre>';
foreach ($obj as $key => $value)
{
echo PHP_EOL . 'obj->' . "$key = " . $value;
}
But upon closer inspection, the code in the third line that begins with <bod> cuts off when it encounters the <em>. The output looks like this:
obj->ttl = This is the Title
obj->sub = This is a sub-title
obj->bod = This is a body with
obj->con = This creates a continue button
I need some help in how to fix this. ]
The third line should look like this:
obj->bod = This is a body with <em>Italics in the middle</em>
Thanks.
An alternative, of course, is to use JSON instead of XML. JSON is much "lighter" as a transport mechanism and is the preferred encoding today.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://php.net/manual/en/function.htmlspecialchars.php