Skip to main content

Posts

Showing posts with the label PHP

Convert excel to CSV file using PHP, Linx Server

How to convert xls file into csv file using php or LAMP, Look at simple example to convert excel to csv file using php on linux server. <?php require_once 'Excel/reader.php'; $excel = new Spreadsheet_Excel_Reader(); $excel->setOutputEncoding('CP1251'); $excel->read('b.xls'); $x=1; $sep = ","; ob_start(); while($x<=$excel->sheets[0]['numRows']) { $y=1; $row=""; while($y<=$excel->sheets[0]['numCols']) { $cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : ''; $row.=($row=="")?"\"".$cell."\"":"".$sep."\"".$cell."\""; $y++; } echo $row."\n"; $x++; } $fp = fopen("data.csv",'w'); fwrite($fp,ob_get_contents()); fclose($fp); ob_end_cl

How To Read RSS Using PHP

Here is the simple code to read RSS Feeds using php with simpladxml_load_string function. CODE: 1 :   <?php 2 :        $displayItems = 5; 3 :        $itemCounter = 0; 4 :        $rss = simplexml_load_file("http://put here url of RSS Feed"); 5 :        foreach($rss->channel->item as $feeds){ 6 :             $itemCounter++; 7 :             echo '<li><a href="'.$feeds->link.'">'.$feeds->title.'</a><br /><br />'; 8 :             if($itemCounter==$displayItems)break; 9 :        } 10 :   ?>

Search Records into XML Using PHP

There is an example for search items or block into xml using php with simplexml_load_string method or function, this will return you record block for particular query. query = us CODE: 1 :   <?php 2 :        # parm query=delhi , us 3 :        $xmlStr = '<?xml version="1.0" encoding="utf-8"?> 4 :                            <temprature> 5 :                            <item> 6 :                                 <city>Bareilly</city> 7 :                                 <state>Uttar Pradesh</state> 8 :                                 <country>India</country> 9 :                                 <lat>32.4567</lat> 10 :                                 <lon>34.4567</lon> 11 :                                 <temp>43.0</temp> 12 :                            </item> 13 :                            <item> 14 :                                 <city>Haldwani</city&

Set Script Timeout In PHP

In PHP.ini define a script timeout (max_execution_time) if it's exceed , the script returns a fatal error. The default limit is 30 seconds. to set script max execution time we can use below function. set_time_limit(1000) //1000 seconds OR ini_set("max_execution_time","1000"); //1000 seconds

Create XML File From Mysql Table

How to create XMLFile Form Mysql Table function createXMLFile($result, $feildLength, $dir) { $headers = array(); $xmlData = array(); $str = ""; $counter = 0; for ($i=0;$i<$feildLength;$i++) { array_push($headers, mysql_field_name($result, $i)); } $xmlFileData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; while ($row = mysql_fetch_array($result)) { for ($i=0;$i<$feildLength;$i++) { $str .= "<".trim($headers[$i]).">" . escapeXMLEntities(trim($row[$i])) . "</".trim($headers[$i]).">\n"; $counter++; //increment column# if ($counter == $feildLength) { //new row array_push($xmlData, "<record>\n" . $str . "</record>\n"); $str = ""; $counter = 0; } } } $xmlFileData .= "<records name=\"Customer_Table\">\n" . implode("", $xmlData) . "</records&g

Create Word Document Using PHP

Here is the example of creating word document using php. <?php $wordObj = new COM("word.application") or die ("Could not create an instance of word"); echo "Version : {$wordObj->version}"; $wordObj->visible = 1; $wordObj->Documents->Add(); $wordObj->Selection->TypeText("Hello World.."); // add text here $wordObj->Documents[1]->SaveAs("sample.doc"); // save location $wordObj->Quit(); $wordObj->Release(); //free object $wordObj = null; ?>

Download Data File From SharePoint

How to download Files From SharePoint Using php? This example is useful to download sharepoint data file using php. I have try to download sharepoint file using PHP CURL and i have done it so try it. <?php $sp_login_id = "test"; // sharepoint user id $sp_password = "********"; //sharepoint password $sp_data_file_url = "http://server/test.doc"; // data file url $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL,$sp_data_file_url); // set url to post to curl_setopt($ch, CURLOPT_USERPWD,"$sp_login_id:$sp_password"); curl_setopt($ch, CURLOPT_FAILONERROR, 1); // curl error curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 5000); // times out after 5s curl_setopt($ch, CURLOPT_GET, 1); // set GET method $result = curl_exec($ch); // execute the whole process //curl errors $curl_info = curl_getinfo($ch); switch($cu