<?php ?>
<?php ?>
<?php ?>
<?php ?>
<?php ?>
<?php ?>
<?php ?>
<?php ?>
PHP is a programming language mainly used for Websites. The Webserver interprets the php code before it shows the page. Thereby you can use the php code to create the web-site. Php is often used in conjunction with a mysql database to format the database output into a readable website. Click here for mysql/php example code.
There are thousands of very useful websites out there about this, but I will show you just some code snippets that illustrate a small portion of what is possible. You can find some links to php coding websites here.
How does this code page work?
Html translates characters differently, as you might know. For example, space " " is not simply a space, but it needs to be written as . There a lot more such examples but for this code page only the indentation is important.
002 if (file_exists('exmaples/condor_q')) {
003 $code = file('examples/condor_q');
004 foreach ($code as $line_numba => $line) {
005 if ($line_numba < 10) {
006 $line_numba = '0'.$line_numba;
007 }
008 $newline = str_replace(" ", " ",htmlentities($line));
009 echo '<span class="code_lines">'.$line_numba.'</span> '.$newlin
e.'<br />';
010 }
011 } else {
012 echo " <p>Couldn't find the file <br />Please contact the webmast
er.</p>";
013 }
014 ?>
type:php [ download ]
Line 1 checks if the file actually exists. If so the file is opened and stored in $code as a list. Line 3 starts the loop over each line of the list, whereas line_numba is the position in the list (or array, if you like). Line 5 adds a leading zero to lines smaller than 10. In line 7 the html formated line will get the spaces replaced by and the result will be stored in $newline. Finally in line 8 the output is created.
Create a pull-down menu from a file
Instead of writing long lines of code for pull-down menus or for picking up the exact same variable, the use of an array holding the variables as keys and the description as value helps a lot.
002 function CreatePullDownMenu($value,$key) {
003 echo '<option value="'.$key.'">'.$value.'</option>';
004 }
005
006 $menus = array( 1 => 'Monday',
007 2 => 'Tuesday',
008 3 => 'Wednesday',
009 4 => 'Thursday',
010 5 => 'Friday',
011 6 => 'Saturday',
012 7 => 'Sunday'
013 );
014 echo '<form action="target.php" method="get">';
015 echo '<select name="menu1">
016 <option value="0">-pull-down-menu-by-php-</option>-';
017 array_walk($menus,'CreatePullDownMenu');
018 echo '</select>';
019 echo '</form>'
020 ?>
type:php [ download ]
result:
