Switching from VB to PHP is half way between the bicycle-to-car switch
and the car-to-car switch. Most things look different so I can remember
which language I am using. One really tricky part is remembering the weird
options on substr(). While substr() is powerful, VBs left(), right() and
mid() are easier to learn. If a programmer has to regularly swap between VB
and PHP, he/she will spend a lot of time looking up the parameters for
substr(). The tip outlined below simply removes the problem.
and the car-to-car switch. Most things look different so I can remember
which language I am using. One really tricky part is remembering the weird
options on substr(). While substr() is powerful, VBs left(), right() and
mid() are easier to learn. If a programmer has to regularly swap between VB
and PHP, he/she will spend a lot of time looking up the parameters for
substr(). The tip outlined below simply removes the problem.
Here are my favorite examples of instant help:
<?php
Function len($lenstring) {
return(strlen($lenstring));
}
// Neat and simple. It lets me grab the length of
// a string exactly how I would in VB:
$x = len($y);
Function
left($leftstring, $leftlength) {
return(substr($leftstring, 0, $leftlength));
}
// It lets me grab 1 or a few characters from
// the front of a string exactly how I would in VB.
Function mid($midstring, $midstart, $midlength="") {
if (len($midlength)) {
return(substr($midstring, $midstring-1, $midlength));
} else {
return(substr($midstring, $midstring-1));
}
}
/*
A little more programming to emulate VB. Mid() is a function I often
use to emulate the sophisticated VB functions that are, sadly, restricted
to only a few versions of VB.
*/
function right($rightstring, $rightlength) {
return(substr($rightstring, -$rightlength));
}
// This is the left function translated for right wingers.
?>
I think you have the idea now. Where something is similar but confusing,
write a function in the new language to emulate the old. In some cases the
process of writing the function will help you learn the new language to the
point where you may never use the emulation function.
write a function in the new language to emulate the old. In some cases the
process of writing the function will help you learn the new language to the
point where you may never use the emulation function.