For GNU/Linux users:
This is a brief howto on writing and running a very simple script on a Linux system.
1). Establish your version of PHP:
a). Open your favourite terminal application or login to a system console, and
b). Type in the command: php -v
c). This will return a system output similar to this:
PHP 4.3.11-pl5-gentoo (cli) (built: Jan 30 2006 19:27:21)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
2). Establish the correct path to your installed and configured PHP:
a). Open your favourite terminal application or login to a system console, and
b). Type in the command: which php
c). This will return a system output similar to this:
/usr/bin/php
3). Now write your script. I used the one above but made some small modifications, by commenting as much as I could, making the default window open in the centre of the viewable screen and using a larger default window size.
Contents of the script: hello.php
#!/usr/bin/php
<?php
if( !extension_loaded('gtk')) {
dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
}
function delete_event()
{
return false;
}
// when window or app is closed, print Shutting down script...
function shutdown()
{
print("Shutting down script...\n");
gtk::main_quit();
}
// when button is clicked, print Hello World!
// and print Shutting down script...
function hello()
{
global $window;
print "Hello World!\n";
$window->destroy();
}
// make new window
$window = &new GtkWindow();
// register destroy as handler for shutdown
$window->connect('destroy', 'shutdown');
// register delete-event as handler for delete_event
$window->connect('delete-event', 'delete_event');
// set window border
$window->set_border_width(100);
// set default size
$window->set_default_size(300,150);
// set screen position
$window->set_position(GTK_WIN_POS_CENTER);
// make new button in window
$button = &new GtkButton('Hello World!');
$button->connect('clicked', 'hello');
$window->add($button);
$window->show_all();
gtk::main();
?>
4). You will notice that the first line of this script is:
#!/usr/bin/php
This is called the hashbang and is used to call the script without having to type the command 'php scriptname.php' all the time.
5). Now finalise and setup the script as executable:
a). Save this script as 'hello'
b). Type the command: chmod a+x hello.php
6). Now to execute the script hello.php, while in the same directory as you saved it to:
a). Type the command: ./hello.php
7). To execute the script hello.php from any other directory on your system, for example the /home/user/script directory:
a). Type the command: ./home/user/script/hello.php
Hope this helps, milites
http://gtk.php.net:80/manual/en/tutorials.hellow.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.