Mike's Technology Blog

Sunday, January 02, 2005

My print_r() implementation for .NET

I notice that print_r() function is missing in .NET, but that's function is very important for debugging your application. So I posted the source code here. I'm open to your suggestions or critiques.

Two MVC frameworks were found today

Actaully, I could have said 'only one' because one of them is for Java and second one is its port for ASP.NET, but let's get down to the business here is the Java one - http://mav.sourceforge.net/ and ASP.NET http://mavnet.sourceforge.net/.

FireFox is getting widespread

I've just had a look at this blog statistics, nearly 50% of the visitors are using FireFox, of course it's because this blog is intendted for web-developers mostly, but it's still surprising.

So what is so special about FireFox? I dunno.......

Creating a PHP-Based Content Management System

As well as usual, I was simply browsing the Net in the morning today and came across something that can interest me and you. This time it was this article - Creating a PHP-Based Content Management System.

It covers some basics of creating a CMS - general plan, some system classes, validation etc. Although I didn't like some things, for example DBConnector class, I would use the Singleton pattern there, plus they don't have a full separation of content and PHP code, that is not good and look like just another Nuke.

But some thing are rally good, for instance their validation class:




class Validator extends SystemComponent {

var $errors; // A variable to store a list of error messages

// Validate something's been entered
// NOTE: Only this method does nothing to prevent SQL injection
// use with addslashes() command
function validateGeneral($theinput,$description = ''){
if (trim($theinput) != "") {
return true;
}else{
$this->errors[] = $description;
return false;
}
}

// Validate text only
function validateTextOnly($theinput,$description = ''){
$result = ereg ("^[A-Za-z0-9\ ]+$", $theinput );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}
}

// Validate text only, no spaces allowed
function validateTextOnlyNoSpaces($theinput,$description = ''){
$result = ereg ("^[A-Za-z0-9]+$", $theinput );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}
}

// Validate email address
function validateEmail($themail,$description = ''){
$result = ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $themail );
if ($result){
return true;
}else{
$this->errors[] = $description;
return false;
}

}

// Validate numbers only
function validateNumber($theinput,$description = ''){
if (is_numeric($theinput)) {
return true; // The value is numeric, return true
}else{
$this->errors[] = $description; // Value not numeric! Add error description to list of errors
return false; // Return false
}
}

// Validate date
function validateDate($thedate,$description = ''){

if (strtotime($thedate) === -1 || $thedate == '') {
$this->errors[] = $description;
return false;
}else{
return true;
}
}

// Check whether any errors have been found (i.e. validation has returned false)
// since the object was created
function foundErrors() {
if (count($this->errors) > 0){
return true;
}else{
return false;
}
}

// Return a string containing a list of errors found,
// Seperated by a given deliminator
function listErrors($delim = ' '){
return implode($delim,$this->errors);
}

// Manually add something to the list of errors
function addError($description){
$this->errors[] = $description;
}

}