From The Blog

PHP: Calculate result of a mathematical expression given in a string

10 September 2012, in

How to calculate the result of a mathematical expression given as a string:

function calc_string( $mathString )
{
$cf_DoCalc = create_function("", "return (" . $mathString . ");" );
return $cf_DoCalc();
}

echo "result is: "calc_string("2+25*3");

//result is: 77



Post a Comment

Parsing XML easily in CakePHP 2

2 June 2012, in

It is very easy to parse XML in CakePHP , here is an example in CakePHP v2

// import XML Utility class
App::uses('Xml', 'Utility');

// your XML file's location
$xml1 = Xml::build('http://url-of-XML');

$xml2 = Xml::build('http://http://url-of-XML', array('return' => 'simplexml'));
// $xml now is a instance of SimpleXMLElement



Post a Comment