This API is not that hard to use even though it is a C API. It is very similar to the SQL functions that are included with PHP out of the box.
Even better, one can utilize existing source code from old turbo pascal programs, delphi programs, freepascal programs etc. Some units such as CRT.pas are not compatible with web programming since they make use of special console functions that aren't available in a web browser (one could go as far as making a webCRT.pas with this functionality if they wished).
In PHP, there is no way to access existing C libraries easily (importing from C DLL's). One can make extensions to the PHP language, but with Powtils your power is limitless. You can use existing C dll's or dso's, you can use existing Pascal code from desktop programs, you can use Pascal dll's, you can use operating system dll's, etc.
// alpha numeric, like 'a'..'z', 'A'..'Z', '0'..'9' in Pascal $AlphNum = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Y','Z', '0','1','2','3','4','5','6','7','8','9','0' ); if ( in_array('a', $AlphNum) ) { echo 'a found <br>'; } else { echo 'a not found <br>'; } if ( in_array('x', $AlphNum) ) { echo 'x found <br>'; } else { echo 'x not found <br>'; } if ( in_array('#', $AlphNum) ) { echo '# found <br>'; } else { echo '# not found <br>'; } if ( in_array('ab', $AlphNum) ) { echo 'ab found <br>'; } else { echo 'ab not found <br>'; }The above is kind of messy, but it is the way PHP language is designed. PHP was generally designed so that regular expressions could be used whenever something like the above situation was needed. That causes bad habits. It is just the syntax and style they offer, and nothing we can do about it.
In Pascal there is a more elegant XYZ in SET syntax.. for example:
Note: set<..> rather should contain square brackets, lufdoc parser needs to be updated.
const AlphNum = <'a'..'z', 'A'..'Z', '0'..'9'> ; // alpha numeric characters begin if 'a' in AlphNum then webwrite('a found <br>') else webwrite('a not found <br>'); if 'x' in AlphNum then webwrite('x found <br>') else webwrite('x not found <br>'); if '#' in AlphNum then webwrite('# found <br>') else webwrite('# not found <br>'); if 'ab' in AlphNum then webwrite('ab found <br>') else webwrite('ab not found <br>');
$str1 = 'testing'.' testing'; for ($i = 0; $i < strlen($str1) - 1; $i++ ) { if ($str1<$i> == 't') { echo 't found'; } // str1<$i> should contain square brackets, lufdoc parser needs to be updated }Not really elegant. Lots of symbols, lots of funny looking stuff just to do something simple. However, that's how they designed the language and that is how it works. Here is the difference in Powerful Web Utilities:
var str1: string; i: integer; begin str1 = 'testing' + ' testing'; for i:= 0 to length(str1) do if str1<i> = 't' then webwrite('t found'); // str1<i> should contain square brackets, lufdoc parser needs to be updated end.Strings in PHP act like zero based arrays of characters (starting at string<0>, so you have to subtract one when looping to the end of the string with strlen(). In Pascal strings are one based arrays (starting at string<1>).
procedure (s: string; sort: procedure); begin s:= 'test'; sort; // call custom sort procedure passed in as parameter sort:= @somethingelse; //assign the sort procedure to something else // do more stuff end;In PHP, it is not as elegant or clean - one cannot assign a sort procedure to a variable. More awkwardly, a variable is assigned to a string, which acts like a function if brackets are used to launch the function. It is possible and do-able in a hackish sort of way.
function foo($x) { echo "x is $x <br>"; } function test($func) { $func(10); } // backwards.. we aren't assigning the procedure, we are assigning a variable $foo = "foo"; // foo is a string, but it can also reference the foo function $foo(5); // Output: x is 5 we are launching the foo function test($foo); // Output: x is 10 echo $foo; // outputs "foo" string, does not try to launch foo()In PHP, AFAIK there is no direct/elegant way to:
test = somefunction; //can't do it test = @someotherfunction // can't do itThe behavior of PHP is odd, and in my opinion much better design choices could have been made for that language. However, that's the way they designed it, and people put up with it. When migrating code or learning about the differences between Powtils and PHP, it is important to have knowledge about these subjects.
In PHP, one might consider it Voodoo or Weird or Very Advanced to pass in a function as a parameter, or assign a function to point to some other function. Modern Pascal programmers consider it an intermediate thing or even common knowledge. Another way to achieve similar behavior is to use an object and reference self.method inside the function - however sometimes object abuse occurs and it is better to pass in a simple function argument.