Quick PHP Tip: How to parse CDATA sections using SimpleXML
Applies to: simplexml_load_string and simplexml_load_file
Problem : SimpleXML does not parse text inside CDATA tags in an XML.
Consider the XML below:
$str = ‘<rootNode>’;
$str.=’<childNode>some text goes here</childNode>’;
$str.=’</rootNode>’;
To parse it we use following syntax:
$xml = simplexml_load_string($str);
On printing it outputs:
SimpleXMLElement Object
(
[childNode] => some text goes here
)
Thats OK. Now the same xml but this time the [...]
Read the rest of this entry >>
FAQ : How to toggle visibility of an html element by javascript
In my previous post, I discussed how we can change the style and/or css class of any html element by JavaScript. We can take advantage of this feature to add functionality where visibility of elements can be toggled. That means clicking a button will change the state of that element from visible to invisible and [...]
Read the rest of this entry >>
FAQ : Problem with javascript function parseInt
JavaScript function parseInt() is used to parse a string and extract the integer from that string.
Therefore if you do parseInt(”200xyz”), it will return 200.
The problem arises when you do the following:
var value = "010";
alert(parseInt(value)); // incorrect: will alert 8
You had expected 10 but what you got is 8.
Weird behavior, you must be thinking.
Actually not.It is [...]
Read the rest of this entry >>
FAQ: calculate number of days between two dates in javascript
From today onwards I am introducing a new category FAQ. It will contain quick solutions and code for common problems developers face daily in javascript and php. Browser compatibility issues specially (Firefox and IE) will also be taken care of.
So here is the first one.
Q) How can I get the difference(number of days) between two [...]
Read the rest of this entry >>

