I wouldnt say PHP programmers will move to Pascal if there were similar functions. Imho every "native compiled language" programmer should be familiar with either PHP or JS+some runtime (such as Node.js).
PHP at server side can cowork with native Pascal apps at client side, this is why I recently have written this zflate unit, because I needed to add a compression to data exchange rountines, and what was available for FPC wasnt enough or was too heavy for my mini-apps.
What other functions would you sugggest to port? Actually there are not that many functions. Im looking at what locutus have:
https://locutus.io/php/Nothing fancy really.
I would choose
- substr(), instead of copy(s, 5, length(s)-5-5) you could do substr(s, 5, -5)
- all hashing functions, including hash() and hash_hmac()
- fopen(), fwrite(), fread() etc; file_put_contents(), file_get_contents()
- strtotime(), date(), time(), microtime()
- hex2bin(), bin2hex()
Here is substr() snippet
program sub;
function substr(str: string; offset: integer; len: integer=0): string;
begin
result := '';
if str = '' then exit;
if len = 0 then len := length(str);
if len > length(str) then len := length(str);
if (offset > 0) and (len < 0) then len := length(str)-offset+len+1;
if (offset < 0) and (len < 0) then len := abs(abs(offset)-abs(len));
if (offset < 0) and (len > 0) then offset := length(str)+offset+1;
if offset+len > length(str) then len := length(str)-offset+1;
if len < 1 then exit;
result := copy(str, offset, len);
end;
var
s: string;
begin
s := 'hello kitty';
writeln('from 3 to the end: ', substr(s, 3));
writeln('2 chars starting from 3 char: ', substr(s, 3, 2));
writeln('all from 3 but last 2 chars: ', substr(s, 3, -2));
writeln('last 3 chars ', substr(s, -3));
writeln('first 3 chars: ', substr(s, 1, 3));
writeln('all but 3 last chars: ', substr(s, 1, -3));
writeln('3 chars starting from char 7: ', substr(s, 7, 3));
readln;
end.