(The output above would be what you get if you called var_dump() on the object. It probably looks more complex than it really is. Basically, to get at "The Simpsons" part, we would write "$simplexml->show[2]->name".)

This is useful because: #1 we save alot of time not having to use the old XML parsing methods (... which isn't difficult, just time consuming), #2: we can "use" this in a "foreach" structure, and #3 it's easier for newbies to learn with.

So, what's the solution. Well, we can turn the CDATA into XML "escaped" text before giving the "XML data" to SimpleXML. In other words, take to CDATA and do the following conversions...

& becomes &amp;
" becomes &quot;
< becomes &lt;
> becomes &gt;

(And of course, drop the "<![CDATA[" and "]]>" too.)

I tried doing this with regular expressions but just couldn't figure out the proper way to represent "not a string". (I tired it with POSIX regular expressions are Perl-compatible regular expressions. But couldn't get anything to work.) So, eventually I just decided to write a function for it. (Which is tedious.) So, here it is. Hopefully it will help everyone else to not get frustrated with SimpleXML being too simple:

// Create the SimpleXML object (not having to worry about loosing info due to CDATA)
$simplexml = simplexml_load_string($xml_data);

Just an extra note. I'm not sure how efficent this is with the use of the str_split() function (to turn a string into an array of characters). But if you are using SimpleXML, you're probably not really worried about that. (Or at least not at that stage of development.)

Hopefully someone will find this useful. (If you find any errors or bugs with it, send me an e-mail and let me know.)

The Proper Way to Use PHP's eval()
Many people say it is bad practice to use the eval() procedure in any language. That there is always a better way to do it. I disagree.

I think that some situations can warrent the use of the eval() procedure. Esspecially if you use it properly and carefully.

The PHP eval() procedure is no different. There are two important rules to remember when using PHP's eval().

Always check the the return value from eval().

Make it so you "code" returns an "OK" signal when it is done.

Let me explain this more. Since you are using "executing" unknown code and really don't know if the code has any syntax errors, or and other errors. You should be making an effort to check for this.

The PHP eval() procedure will return FALSE if there us an error. Therefore, you should check to see if it returns FALSE. So, you should be doing something like:

However, it is possible that eval() could return FALSE, even if it did not have this kind of error. So, you must set up your code so returns something other than FALSE when there is no error. I suggest it returns TRUE. You can do this by doing something like: