WebDNA vs. PHP


The best way to show the difference between the two languages is to compare the code required to do the same thing. Even a non-techie can see what's going on in the WebDNA example.

Do you want a directory file listing, with files and only files, removing unauthorized files and showing no file extension? There's a simple beauty in typing:
[listfiles path=./][showif [isfile]=T]
[if ("[fileName]" ^ ".png")|("[filename]" ^ ".swf")]
[then]
[grep search=\..*&replace=][filename][/grep]<br>
[/then]
[/if][/showif][/listfiles]


as opposed to unintuitive PHP code:

<?php   
function strip_ext($name) {
$ext = strrchr($name, '.'); 
if($ext !== false) { 
$name = substr($name, 0, -strlen($ext)); 
}
return $name;
}
function removeHyphen($filename) {
$target = $filename;
$patterns[0] = '/-/';
$patterns[1] = '/_/';
$replacements[0] = ' ';
$replacements[1] = ' ';
$filename = preg_replace($patterns, $replacements, $target);
return $filename;
}
function capFirstWord($word) {
$cap = $word;
$cap = explode(' ', $cap);
foreach($cap as $key => $value) {
$cap[$key] = ucfirst($cap[$key]);
}
$word = implode(' ', $cap);
return $word;
}
function formatFile($name) {
$name = strip_ext($name);
$name = removeHyphen($name);
$name = capFirstWord($name);
return $name;
}
$mydir = dir('./');
$extension_blacklist = array("gif", "js", "css");
$filter = array("config.php", "printpage.php");
while (($file = $mydir->read()) !== false)
{
$file_info = pathinfo($file);
if ($file != "." && $file != ".." && !in_array($file, $filter) && !in_array($file_info['extension'], $extension_blacklist))
if(!is_dir($file))
{
echo "<li><a href='./$file'>".formatFile($file)."</a></li>";
}
}
$mydir->close();
?>


Here another PHP vs. WebDNA example.

-Christophe Billiottet
Download WebDNA Now WebDNA runs on Windows, OSX, Linux and Solaris
 
Home | Contact | Support | Free Download | Developer Resources | Community Forum | Learn | Training | News | Community | Store | SiteMap
© Copyright 2010 WebDNA™ Software Corporation. ALL RIGHTS RESERVED - 16192 Coastal Highway, Lewes, DE 19958