I would highly recommend Aptana due to its ability to incorporate with other languages such as xhtml, javascript, and css, along with php. The included validation tools are a great plus. The basic version is free.
Vytvořte soubor nazvaný hello.php a vložte ho do kořenového adresáře vašeho webserveru (DOCUMENT_ROOT). Soubor bude mít následující obsah:
Příklad 2.1. Náš první PHP skript: hello.php
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Ahoj světe</p>'; ?>
</body>
</html>
Pro přístupu k souboru použijte váš webový prohlížeč, zadejte do něj URL serveru zakončený "/hello.php" (odkazem na soubor). Vyvíjíte-li lokálně, bude URL něco jako http://localhost/hello.php nebo http://127.0.0.1/hello.php, ale záleží to na konfiguraci serveru. Je-li všechno nakonfigurováno správně, soubor bude parsován interpretem PHP a ten pošle do vašeho prohlížeče tato data:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<p>Ahoj světe</p>
</body>
</html>
Tento program je extrémně jednoduchý a k vytváření takových stránek opravdu nepotřebujete PHP. Vše, co to udělá, je zobrazení Ahoj světe za použití PHP příkazu echo(). Uvědomte si, že soubor nemusí být spustitelný ani jinak speciální. Server zjistí, že tento soubor má být interpretován prostřednictvím PHP, protože má příponu ".php", kterou má server nakonfigurovánu k předávání do PHP. Uvažujte o tom jako o normálním HTML souboru, který vám poskytuje sadu zvláštních značek dělajících mnoho zajímavých věcí.
Pokud byste vyzkoušeli tento příklad a nic by se nevypsalo, vyskočil by dialog na stažení souboru nebo by byl vidět obsah souboru jako text, znamená to, že server, na kterém to zkoušíte, nemá (zapnutou) podporu PHP nebo není správně nakonfigurován. Požádejte administrátora, aby podporu zapnul za pomoci kapitoly Instalace z tohoto manuálu. Vyvíjíte-li lokálně, také si přečtěte kapitolu o instalaci, abyste se ujistili, že je vše správně nakonfigurováno. Přesvědčte se, že soubor voláte protokolem HTTP ze serveru, který ho poskytuje. Pokud byste soubor volali přímo (přes souborový systém), nebyl by parsován PHP. Pokud problémy přesto přetrvají, nestyďte se použít některou z možností » PHP podpory.
Cílem příkladu je ukázat speciální formát PHP značek. V tomto příkladu používáme k označení začátku PHP značku <?php. Pak vložíme příkaz PHP a opustíme PHP režim přidáním zavírací značky ?>. V HTML souboru můžete skákat dovnitř a ven z PHP režimu kdykoli chcete. Pro detailnější informace si přečtěte manuálovou sekci základní syntaxe PHP.
Poznámka ke koncům řádků: Konce řádků mají v HTML malý význam, přesto je však dobré vytvářet HTML kód tak, aby vypadal pěkně a čistě, vkládáním konců řádků. Odřádkování následující bezprostředně po uzavírací značce ?> bude v PHP odstraněno. To může být extrémně užitečné, pokud vkládáte mnoho bloků PHP nebo inkludujete soubory obsahující s PHP kódem, které nejsou určeny ke generování výstupu. Současně to ale může být trochu matoucí. K vynucení odřádkování můžete za uzavírací ?> vložit mezeru, nebo přidat explicitní odřádkování do posledního echo/print v PHP bloku.
Poznámka k textovým editorům: Existuje mnoho textových editorů a integrovaných vývojových prostředí (IDE), které můžete používat k tvorbě, úpravám a správě PHP souborů. Částečný seznam těchto nástrojů je udržován na » Seznam editorů PHP. Přejete-li si doporučit editor, navštivte prosím výše uvedenou stránku a požádejte jejího správce, aby přidal editor do seznemu. Může být užitečné používat editor se zvýrazněním syntaxe.
Poznámka k textovým procesorům: Textové procesory jako StarOffice Writer, Microsoft Word a Abiword nejsou vhodné pro editaci PHP souborů. Přejete-li si použít některý z nich pro tento testovací skript, musíte se ujistit, že soubor ukládáte jako holý text, jinak PHP nedokáže přečíst a vykonat skript.
Poznámka k poznámkovému bloku na Windows: Píšete-li své PHP skripty v poznámkovém bloku Windows, musíte se ujistit, že soubory ukládáte s příponou ".php". (Pokud neprovedete některý z následujících kroků, poznámkový blok automaticky přidá příponu ".txt"). Ukládáte-li soubor a jste tázáni na jeho název, dejte tento název do uvozovek (např. "hello.php"). Alternativně můžete rozbalit seznam typů souborů v dialogu a změnit typ z "Textové dokumenty" na "Všechny soubory". Pak lze vložit název souboru bez uvozovek.
Nyní, když jste úspěšně vytvořili fungující PHP skript, je čas vytvořit nejoblíbenější PHP skript! Zavolejte funkci phpinfo() a uvidíte množství užitečných informací o vašem systému a jeho nastavení, jako jsou dostupné předdefinované proměnné, načtené moduly PHP a konfigurační nastavení. Udělejte si chvíli času a tyto důležité informace si prohlédněte.
Vaše první stránka v PHP
09-Sep-2008 07:28
08-Jul-2008 05:30
also I just started using HomeSite which is also a very good and simple to use editor. It compliments Dreamweaver quite well.
24-Jun-2008 03:14
Always been happy with the facilities available in Dreamweaver (cur CS3), although the footprint on your PC can be high so notepad++ comes in second for little use of PC resources.
08-Jan-2008 01:30
The most usefull editor for me is Eclipse PDT and the debugger provided by Zend to the open source community.
Please check: http://www.zend.com/en/community/pdt
http://www.eclipse.org/pdt/
It's not only an editor, but an IDE also.
Good luck!
BN
01-Jan-2008 07:46
For text editors, my current favorites are Bluefish on Linux, and Notepad++ on Windows. I believe you can't go wrong with these (and I believe Bluefish is available in many Linux distributions in pre-packaged form). I'm not affiliated with either of these; I'm just a satisfied user.
http://bluefish.openoffice.nl/
http://notepad-plus.sourceforge.net/uk/site.htm
10-Sep-2007 12:51
Re: .txt extensions at the end of Notepad files
I am not a programmer, but I do know that when you ftp files to a server, not only is the real name of the file shown that you want to transfer, but you can change it to whatever you want on the other end. I know that can make uploading a lot of files a pain, but then, I have never had to upload that many files. I remember a long time ago having to change .htm to .html, but I have never encountered the problem of having a .txt added that I didn't want.
19-May-2007 01:48
Well, but PHP file ownership is important when server has safe_mode enabled - HTTP server checks it, uses it to set UID of process which executes it, or may even refuse to execute such a file - e.g. if one user is owner of main PHP file, and the main file includes another, owned by other user, this is considered to be security violation (quite reasonably).
12-Apr-2007 07:29
I noticed that it mentioned to add a "double quote" i.e "hello.php", when saving a php file when the drop down menu says txt. It is not necessary. You can type the whole name without quotes when the drown down menu is either txt or all. UNLESS, maybe for older windows? But for newer windows, it is not necessary. It works without a double quote. Anyway, if double quote is mentioned in the manual, then window versions needs to be stated.
18-Mar-2007 11:56
People with file extension woes on Win32 really just need a better text editor. Notepad2 is easy, very like notepad and supports syntax highlighting; quite a neat little thing:
http://www.flos-freeware.ch/notepad2.html
...and it won't mangle your file extensions. Of course there are lots of others, but I use this one at work and it's OK when you have to work on Windows toasters. Of course EMACS is also available on Win32 for those who like that sort of thing but Notepad2 is a neat, minimal, easy to use app for those who are generally comfortable in the Windows environment and might be intimidated by EMACS.
05-Jan-2007 11:55
No need to go through these contortions each time to make sure the file is properly saved with the .php extension. Just register .php as a file type in Windows, and then saving as hello.php without the quotes will work fine.
09-Aug-2006 07:12
On Windows, if file extensions can be hidden, you may not SEE that you have accidently saved a file as 'Text Documents' (and that the browser has added '.txt' to the end of your 'page.html', resulting in 'page.html.txt'.) You still see only 'page.html' even though it's really 'page.html.txt'. Also, if you try to rename it, it won't work because it's not overwriting the '.txt' part and not changing the filetype.
By the way, the hiding of file extensions is ALSO a way malicious crackers get you to click on an executable virus, fooling you into thinking it's an innocent document. You should always be able to view the extensions of all files on your system.
To view all extensions, open Windows Explorer. Click the 'Tools' menu, then 'Folder Options'. In the dialog box that appears, click the 'View' tab. In the 'Advanced Settings Box', scroll down to 'Hide extensions for known file types' and click the checkbox next to it to REMOVE THE CHECKMARK. Click the 'Apply to All Folders' button near the top of the dialog. This may or may not take a few minutes. Then click the 'OK' button to close the dialog.
Now, if something accidentally gets saved as the wrong filetype, resulting in another file extension automatically appended to the one you typed, you will see it and be able to rename it.
Of course, a badly-named file can be renamed simply by using 'Save As' and saving it as the proper filetype, but if you can't see the file extension, you may not know that is the problem. Also, renaming is easier than opening, resaving as a new filetype, and then deleting the old version!
07-Jun-2006 03:26
document_root variable is located in your web server configuration file
18-Jan-2005 02:25
OS X users editing in TextEdit will need to make sure their TextEdit preferences are set to allow plain text files. Under the TextEdit pull-down menu, choose PREFERENCES, then under NEW DOCUMENT ATTRIBUTES in the window that pops up, click PLAIN TEXT.
Then, in the section of that same window called "saving," DESELECT "append .txt extension to plain text files." This will allow you to save your files with a .php extension.
Then close the PREFERENCES window. You're good to go.
10-Aug-2004 11:47
Expansion on saving w/ notepad/wordpad: (tested on XP; but should work on 2000,NT, and 98)
You can associate the .php file extension w/ Windows w/o going into the registry.
Open up My Computer or MSIE in file mode. Go to folder options > File types tab. Now click new. Add the extension as PHP or php. If you can't find the PHP application in the dropdown list under advanced, just go OK, for now. At least the extension is in place.
Now, try and create a php file by using the directions from this page of the PHP tutorial (should save it with the rest of your HTML files, i.e. your DocumentRoot). If you go to view your php file listed in the directory, and you see that it's still a .txt file, right-click the icon to see if you can locate "open with." If so, you should be able to browse for the appropriate file, which should be at (may vary, depending on where you installed PHP):
C:\PHP\php.exe
Click that as the default program, and the PHP logo should appear on all your scripts, and no problems saving should occur w/ any program.
Good luck.
03-Feb-2003 11:18
Note on permissions of php files: You don't have to use 'chmod 0755' under UNIX or Linux; the permissions need not be set to executable. Again, this is more like a html file than a cgi script. The only mandatory requirement is that the web server process has read access to the php file(s). With many Linux systems, it is popular for Apache to run under the 'apache' account. Given that HTML and other web files, like php, are often owned by user 'root' and group 'web' (or another similar group name), acceptable permissions might be those achieved with 'chmod 664' or 'chmod 644'. The web server process, running under the 'apache' account, will inherit read only permissions. The 'apache' account is not root and is not a member of the 'web' group, so the "other" portion of the permissions (the last "4") applies.
