php: read directory
2019-12-29 2019-12-30 07:26:47

PHP,directory,regex,array,EN

here are different ways to read a directory with php.

current level

using array_diff & scandir: read /var/www/Foo/ and ignore .dot files

$aContent = array_diff(scandir ('/var/www/Foo/'), array('..', '.', '.htaccess', '.htpasswd'));

using preg_grep & scandir: read /var/www/Foo/

$aContent = preg_grep('/^([^.])/', scandir('/var/www/Foo/'));

_using 3 array* functions & scandir: read and ignore .dot files […]


php: generate a 60 char random string
2019-12-29 2019-12-29 22:02:11

PHP,string,EN

Q: how to create a 60 char random string ?

A: use the benath function generateRandomString() to create such a string. Modify to your needs.

usage

$srandomString = enerateRandomString();

it will produce a sting like:
1572437300-71425db97d34ae5da7-37619268-DSCbkJT0JoqHpPtsCiN1l


/**
 * @return string
 */
function generateRandomString()
{
    $iLength = 30;
    $sBase = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     […]

This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".