Posts

Showing posts with the label Php

Multiple Worksheets, Borders, and Images

Few months back I was searching for the php code that creates excel file, which has got the content in multiple worksheet. I couldn't get any help from the net. Today just going through the PEAR Modules, I came across this script. This script generates excel file with multiple worksheets. <?php require_once 'Spreadsheet/Excel/Writer.php'; $workbook = new Spreadsheet_Excel_Writer(\"example4.xls\"); $worksheet =& $workbook->addWorksheet();\n $worksheet->writeNote(1, 0, \"Invoice For New Customer 1\"); $worksheet->setRow(0, 50); //$worksheet->insertBitmap(0, 0, \"logo.bmp\", 0, 0); $left =& $workbook->addFormat(array(\"Left\" => 2)); $right =& $workbook->addFormat(array(\"Right\" => 2)); $number =& $workbook->addFormat(array(\"NumFormat\" =>'$####.00')); $worksheet->write(1, 1, \"Client Name:Shakeel Shrestha\"); $worksheet->write(2,

Extracting Information Using XPath

PYou want to make sophisticated queries of your XML data without parsing the document node by node. Solution: Use XPath XPath is available in SimpleXML <?php $s=simple_load_file('address-book.xml'); $emails=$s->xpath('/address-book/person/email'); foreach($emails as $email){ //do something with $email } ?> And in DOM <?php $dom=new DOMDocument; $dom->load('address-book.xml'); $xpath=new DOMXPath($dom); $email=$xpath->query('/address-book/person/email'); foreach($emails as $email){ //do something with $email } ?> As your XML files become increasingly complex and your parsing desires grow, using XPath is easier than filtering the data inside a foreach. PHP has an XPath class that takes a DOM object as its constructor. You can then search the object and receive DOM nodes in reply. SimpleXML also supports XPath, and it's easier to use because it's integrated into the SimpleXML object. DOM supports XPath

Currency Conversion With foxrate.org's XML-RPC API

Foxrate.org provides XML-RPC API to convert the currency from one to another. I needed it for a project to convert from Euro to Pound and vice-versa. I had once read about such a work in roshanbh.com.np so I finally thought to follow the same API. After searching for some days, I came up with some code but had some problem for which I couldn't get any help. At last our friend from college, Sanjeev, added last two lines of code to make it run. Thanks Sanjeev. <?php require_once('lib/xmlrpc.inc');//initialize client $xmlrpc_client=new xmlrpc_client('/rpc','www.foxrate.org',80); $xmlrpc_client->setDebug(3);//turn on debugging mode //construct the request (xml-rpc message) $xmlrpc_msg=new xmlrpcmsg('foxrate.currencyConvert', array(new xmlrpcval('USD','string'), new xmlrpcval('EUR','string'), new xmlrpcval(1,'double'))); //send the request $xmlrpc_resp=$xmlrpc_client->send($xmlrpc_msg); //working