09.07.2008 14:25
I'm not in search of a full-time job in Berlin, but still like to test my skills, so the following code hopefully gets properly displayed:
<code class="hilite-php">
<?php /* give the kid a name: Good code v1.0 *//* shorthands '<?' are bad coding style;
also I like my settings at the begin of the file, not just anywhere in-between */// init
$roles['andi'] = 'Developer'; /* missing quotes for the key - and no reason to use double quotes */
$roles['detlef'] = 'Boss'; /* same as above */$list[] = 'Apple';
$list[] = 'Peach';
$list[] = 'Orange';// alternatively we could have used $list = array('Apple', 'Peach', 'Orange');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Some rather crude skill test</title>
<style type="text/css">
body {
font-family: "Times New Roman", serif; /* serif was missing */
background-color: #fff; /* unix default usually AINT white! */
color: #000; /* better be safe than sorry */
}.strongemphasis {
font-weight: bold;
font-style: italic;
}
</style>
</head>
<body>
<h1><img src="images/logo.gif" alt="Proper Company Name or title" /></h1><!-- no need for aligning the image to the left - thats the DEFAULT setting for most browsers (except arabian; how the chinese/japanese do I dont know out-of-the-box) --><h2>Hello <?php
if(array_key_exists(trim(strip_tags[$_GET['user'])), $roles) != false) {
echo $roles[trim(strip_tags($_GET['user']))]; /* do at least SOME sanitizing! */
} else {
echo 'unknown User';
} ?>!</h2><?php
if(is_array($list) != false && sizeof($list) > 0) { /* does the variable exist, is it an array and does it contain something? */ ?>
<ul><!-- missing list container, eg. Unordered List -->
<?php
foreach($list as $list_count => $list_item) { /* who needs a for-loop if you simply could use a foreach? */
?>
<li class="strongemphasis"><?php echo $list_item; ?></li>
<?php
}
?>
</ul><!-- /missing list container -->
<?php
} else { /* some proper error message / excuse if no data are available */ ?>
<p class="preformated-code">Sorry, but there are no data given to output.</p>
<?php
}
?>
</body>
</html>
</code>
Be the first to write a comment!