Mike Borozdin's Blog

A blog about programming, web and IT in general

NetBeans 6.5 as a Cute and Free IDE for PHP

Although I mostly blog about .NET and related technologies, tools, etc., this time I’m writing about PHP. I work a lot with PHP as well. And recently I got a small project to do and I was looking for a free but cute PHP IDE. I’m quite aware about Eclipse and PHP Development Tools for Eclipse, but I still was wondering if there is some other free tool for PHP. Eventually, I remembered NetBeans.

NetBeans is mostly known for Java developers as a good and free IDE. At the same time recently NetBeans started supporting other languages, like C/C++, Ruby and finally PHP. Moreover it not only supports plain PHP, but it offers quite good support of HTML and JavaScript.

Ok, what do I mean by the term of “support”? I mean a standard set of features that every IDE must provide:

  • Project based structure
  • Code completion
  • Code navigator
  • Error checking while typing
  • Debugging
  • Versioning

So, NetBeans has it all. Furthemore, it works greatly with JavaScript that was a quite a surprise for me after a while working of with Eclipse. So, NetBeans has a nice code completion feature for JavaScript as well, that will understand your and 3rd party libraries, jQuery, for instance.

javascript

Then, NetBeans enables you to interact with databases straight from the IDE. You can connect to MySQL server and create a table for example.

createtable

 

Generally, I feel pretty good about NetBeans. It seems to be working much faster than Eclipse, both in terms of the loading time and in terms of code editing and code completion as well. I guess I’d better draw a comprehensive feature comparison with Eclipse PDT, but I will do that next time.

Now I just want to recommend anyone who is looking for a decent free IDE for PHP to give NetBeans a try. If you don’t need to write Java code, you can download a PHP only package that is just about 25 MB that is far lighter than the mentioned PDT.


Tags:
Posted by Mike Borozdin on Saturday, February 07, 2009 2:50 PM GMT
Shout it Kick it!  
Permalink | Comments (17) | Post RSSRSS comment feed

Develop PHP in Visual Studio

I've been programming with PHP for many years and have used a lot of editors and so-called IDEs, I must admit that PHP IDEs have become much better now and they differ significantly from simple editors with syntax highlighting. Anyway, in the recent time I have been working much with Visual Studio. I must confess that I really love it, some people may argue of course, especially Java developers who are fond of their development tools and tend to look down at other ones. So, I was happy to learn that there is a plug-in that enables you to program with PHP in a familiar development environment of Visual Studio. Sure, I doubt that it will interest people who don't have Visual Studio, but for developer who are used to it, it's a great choice, I think.

It offers solution and project management, IntelliSense, built-in Apache and PHP (you can work with an external server as well), DBG and xDebug debuggers I especially love its debugging features because I deal with the Visual Studio debugger that I love very much. I suppose VS lovers are going to appreciate this feature.

So, if you are a programmer who use Visual Studio and love it and have to use PHP as well, then I think you should give VS.PHP (yeah, that's how it is called) a try. It's available for both Visual Studio 2005 and 2008. There is a 30 days trial. While the full version costs only $99.99 that is not that much comparing to other PHP IDEs, like Zend Studio or NuSphere PHPEd.

I almost forgot to mention, it has built-in Zend Framework as well :-)!


Posted by Mike Borozdin on Sunday, September 07, 2008 2:46 PM GMT
Shout it Kick it!  
Permalink | Comments (3) | Post RSSRSS comment feed

.aspx extension instead of .php? WHY???

This story is not a debate on "ASP.NET vs PHP", but this story is about the people who develop their web applications with PHP, but pretend that they are using ASP.NET. Yes, such people do really exist. I came across their posts in the forums, where they said that or asked how to change the extension of PHP scripts to .aspx.

Why on Earth are they doing that? Basically, they want to look more serious. For some reason, .aspx looks more sophisticated, serious and more enterpisy. The reason is actually well known, ASP.NET usually powers well known companies that everybody look up to.

However, often it's not the developers who want to "be more serious", but their clients who either demand the pages to have the ".aspx" extension or want to the web site to be written with ASP.NET. The latter is the worst case, I believe, because in such a situation, the developer lies to his client. He was hired to build a web site with ASP.NET, but in fact he does with PHP or with something else. I think it is really a lack of work ethic.

This post is partly inspired by the Rick Strahl's article, which is called "ASP.NET gets no Respect", where he puts his thoughts regarding that fact that people and especially the young developers, who are eager to launch their start-up project, simply disregard ASP.NET and prefers to use a more fashionable platform, like Ruby on Rails. While I agree with him on this point, there are people do an opposite thing - write their web sites with PHP and put the ".aspx" extension at the end of their files. <irony>Well, the world is really ridiculous...</irony>


Tags: ,
Posted by Mike Borozdin on Friday, August 15, 2008 7:54 AM GMT
Shout it Kick it!  
Permalink | Comments (18) | Post RSSRSS comment feed

Is PHPLinq As Cool As Real LINQ?

I read about the PHP Implementation of LINQ called PHPLinq. Frankly, I was sceptical about it. Finally, I gave it a try. I still remain sceptical...


Let’s me explain why. Take a look at this fairly simple example, where we extract all the numbers greater than 5:

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '../PhpLinq/Classes/');
require_once('PHPLinq/LinqToObjects.php');

$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

$result = from('$number')->in($numbers)
            ->where('$number => $number > 5')
            ->select('$number');

print_r($result);           

?>

If you familiar with LINQ, then you may say: "Wow, that’s cool! Just like in .NET". Yes, the syntax is quite familiar. But if you look closer, you will notice that the query expressions are encloced in single quotes, i.e. they are just string. That makes a significant difference between PHPLinq and real LINQ. Do you remember what LINQ stands for? It stands for Language Intergrated Query. Unfortunately, PHPLinq isn’t a language integrated query, since it’s not supported by the language natively and we have to use strings for writting queries.

When we write real LINQ queries in Visual Studio we’ve got syntax highlighting, we’ve got IntelliSence and that is more important we can track errors at the compilation stage. PHPLinq lacks all these things. Ok, PHP is an interpreted language, so there’s no compilation stage; however there are smart IDEs that track errors while we’re writing code.


I want to illistrate this, let’s make a deliberate error, we’ll change $number to $number1 in the from clause. If you run the script you’ll get a notice, in case notices are enabled and nothing more.But if you are writing this in C#, it won’t even get compiled.


In the real world LINQ is used mostly as a SQL replace, we don’t have to write the queries in strings anymore and catch the exceptions when running an application. But unfortunately we cannot do the same with PHPLinq, it still forces us to put the queries into strings.


Well, I think I was sceptical enough about it, but still PHPLinq has some cool features, just check this example taken from the PHPLinq official web site:

<?php
/**
 * PHPLinq
 *
 * Copyright (c) 2008 PHPLinq
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPLinq
 * @package    PHPLinq
 * @copyright  Copyright (c) 2008 PHPLinq (http://www.codeplex.com/PHPLinq)
 * @license    http://www.gnu.org/licenses/lgpl.txt    LGPL
 * @version    0.3.0, 2008-06-23
 */

/** Error reporting */
error_reporting(E_ALL);

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');

/** PHPLinq_LinqToObjects */
include 'PHPLinq/LinqToObjects.php';

// Custom class
class Employee {
    public $Name;
    public $Email;
 
    public function __construct($name, $email) {
        $this->Name     = $name;
        $this->Email     = $email;
    }
}

// Create data source
$rssFeed = simplexml_load_string(file_get_contents('http://blog.maartenballiauw.be/syndication.axd'));
$result = from('$item')->in($rssFeed->xpath('//channel/item'))
            ->orderByDescending('$item => strtotime((string)$item->pubDate)')
            ->take(2)
            ->select('new {
                            "PostTitle" => (string)$item->title,
                            "PostAuthor" => (string)$item->author,
                            "MetaData" => new {
                                                "Url" => (string)$item->link,
                                                "Guid" => (string)$item->guid,
                                                "PostDate" => strtotime((string)$item->pubDate)
                                          }
                      }');
               
print_r($result);


Tags: ,
Posted by Mike Borozdin on Friday, July 04, 2008 2:45 PM GMT
Shout it Kick it!  
Permalink | Comments (9) | Post RSSRSS comment feed

PHPExcel: Manipulate Excel Spreadsheets with PHP on Linux

Have you ever faced a situation when you need to manipulate Excel spreadsheets with PHP on the server that is running Linux? If you had a Windows Server you could use PHP COM extensions. However they are unavailable on Linux.


Hopefully, there is a solution. It is called Open XML. It’s a new format of Microsoft Office documents introduced in Microsoft Office 2007. Basically, an Open XML file is a ZIP archive that contains XML files that represent the document mark-up. You can view it yourself or read some documentation, my article isn’t about Open XML, but about the PHP library for working with Excel 2007 files. It also supports Excel 97 format by incorporating a PEAR library.


The library is called PHPExcel. It allows you to read/write Excel spreadsheets, save them in many formats including PDF and HTML. It supports formulas,styles and etc.

It requires:

  • PHP 5.2+
  • GD extension
  • XML extension
  • ZIP extension


I have these two simple examples that show you how to create an Excel spreadsheet and save it in several formats and how to read a spreadsheet and display it on the HTML page.

Writing:

<?php

//Here we set the include path and load the librarires
set_include_path(get_include_path() . PATH_SEPARATOR . '../PhpExcel2007/Classes/');
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');

$excel = new PHPExcel();
$excel->setActiveSheetIndex(0); //we are selecting a worksheet
$excel->getActiveSheet()->setTitle('Products'); //renaming it

//here we fill in the header row
$excel->getActiveSheet()->setCellValue('A1', 'Title');
$excel->getActiveSheet()->setCellValue('B1', 'Price');
$excel->getActiveSheet()->setCellValue('C1', 'Quanity');
$excel->getActiveSheet()->setCellValue('D1', 'Total price');

//here we put some values
$excel->getActiveSheet()->setCellValue('A2', 'Fictional TV set');
$excel->getActiveSheet()->setCellValue('B2', 300);
$excel->getActiveSheet()->setCellValue('C2', 1500);
$excel->getActiveSheet()->setCellValue('D2', '=B2*C2'); //this is how we put formulas, just like using Excel

$excel->getActiveSheet()->setCellValue('A3', 'Fictional mobile phone');
$excel->getActiveSheet()->setCellValue('B3', 200);
$excel->getActiveSheet()->setCellValue('C3', 5000);
$excel->getActiveSheet()->setCellValue('D3', '=B3*C3');

$excel->getActiveSheet()->setCellValue('A4', 'Fictional laptop');
$excel->getActiveSheet()->setCellValue('B4', 1000);
$excel->getActiveSheet()->setCellValue('C4', 2000);
$excel->getActiveSheet()->setCellValue('D4', '=B4*C4');

//some summarizing formulas
$excel->getActiveSheet()->setCellValue('C5', '=SUM(C2:C4)');
$excel->getActiveSheet()->setCellValue('D5', '=SUM(D2:D4)');

//Now we save the created document in the Exce 2007 format
$excelWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$excelWriter->save('Products.xlsx');

//in PDF
$pdfWriter = PHPExcel_IOFactory::createWriter($excel, 'PDF');
$pdfWriter->save('Products.pdf');

//in HTML
$htmlWriter = PHPExcel_IOFactory::createWriter($excel, 'HTML');
$htmlWriter->save('Products.html');

//and in the old binary format
$excelBinaryWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$excelBinaryWriter->save('Products.xls');

?>

 

Reading:

<?php

//Here we set the include path and load the librarires
set_include_path(get_include_path() . PATH_SEPARATOR . '../PhpExcel2007/Classes/');
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');

$excelReader = PHPExcel_IOFactory::createReader('Excel2007'); //we instantiate a reader object
$excel = $excelReader->load('Products.xlsx'); //and load the document

print('<table border="1">');
for ($i = 2; $i < 5; $i++) {
    print('<tr>');
   
    print('<td>');
    print($excel->getActiveSheet()->getCell('A' . $i)->getValue()); //this is how we get a simple value
    print('</td>');
   
    print('<td>');
    print($excel->getActiveSheet()->getCell('B' . $i)->getValue());
    print('</td>');
   
    print('<td>');
    print($excel->getActiveSheet()->getCell('C' . $i)->getValue());
    print('</td>');
   
    print('<td>');
    print($excel->getActiveSheet()->getCell('D' . $i)->getCalculatedValue()); //this is how we get a calculated value
    print('</td>');
   
    print('</tr>');
}

print('<tr><td>&nbsp;</td><td>&nbsp;</td>');
print('<td>' . $excel->getActiveSheet()->getCell('C5')->getCalculatedValue() . '</td>');
print('<td>' . $excel->getActiveSheet()->getCell('D5')->getCalculatedValue() . '</td></tr>');
print('</table>');

?>

 

Conclusion

PHPExcel is a very poweful library which is easy and well documentated. Of course you can use it not only on Linux, but on any operating system, including Windows.


Tags:
Posted by Mike Borozdin on Monday, June 30, 2008 3:20 PM GMT
Shout it Kick it!  
Permalink | Comments (4) | Post RSSRSS comment feed