A PHP script can be very simple or very complex. However, even writing a complex PHP script is relatively simple, requiring only an regular text editor. PHP code is plain text and can be created in any text editor, such as Notepad on Windows or TextEdit on Mac OS X. Anyway, it's indicated and more efficiently to use a dedicated script editor like Notepad++ or Eclipse.
PHP is a programming language that needs a server to run it. First, you must have installed a server, for example Apache and the PHP module. They are free, but for beginners is better to install an all-in-one packages free aplication, like WampServer (www.wampserver.com/en/) or XAMPP, that already has Apache, PHP, MySQL and phpMyAdmin included and configured.
You can get XAMPP from the page: Download XAMPP.
- Once you have installed XAMPP (WampServes or EasyPHP) aplication, you need to create your PHP files in a location where the web server can process them. Normally, this means that the files should be in the serve`s directory root or a subfolder of the document root. The default location of the document root for these aplications is as follows:
<?php ?>- This is a start code and displays nothing.
Any text outside of the PHP tags is immediately sent to the Web browser as regular HTML text.
<?php echo 'The text that appears in your browser.'; ?>Save the file with a name with the ".php" extension (for example "test1.php"), in the proper directory of your Web server, "xamp/htdocs/" (or "wamp/www/").
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Test 2 PHP</title> </head> <body> <?php echo "<h4>Example of a PHP scripts included in HTML</h4>"; ?> </body> </html>- If you save this code in a ".php" file (for example, "test_html.php"), in the server's directory root, and access it in your browser (http://localhost/test_html.php), you'll see in the Web browser the fallowing result:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title> <?php echo 'Page title'; ?> </title> </head> <body> <?php echo '<div>Free PHP-MySQL course: https://coursesweb.net/php-mysql/</div>'; ?> </body> </html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Comment PHP</title> </head> <body> <?php // This is an one-line comment echo '<h3>coursesweb.net</h3>'; /* This is a multiline comment block */ ?> </body> </html>
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net