Archive for July 2019

Php determine every 5th record in interation

<?php   $x = 5;   for($i=0; $i<10; $i++) { if($i % $x == 0) { echo ‘yes’; } } Result: yes yes Explanation: 5 % 5 has remainder 0 (fully divided), 10 % 5 has remainder 0 (fully divided)

Split file and having header kept in all generated files

head -n 1 upload_images.csv > header.csv; tail -n +2 upload_images.csv | split –numeric-suffixes=1 –additional-suffix=.csv -l 320 – –filter=’sh -c "{ head -n1 header.csv; cat; } > $FILE"’ split filename.csv –numeric-suffixes=1 –additional-suffix=.csv -l 50 Result: 50 files named as x{number}.csv

Regex keep only alphanumeric characters with unicode support

echo preg_replace("/[\W]/u", "", $str);

About Unicode

UCS-2 is old encoding standard. It uses fixed size per encoded character and therefore is not compatible with ASCII. UTF-8 is newer standard. It uses dynamic size between 8 – 32 bits per encoded character and is compatible with ASCII. Я так понял что UCS-2 ещё называют UNICODE т.к. каждый символ это полные 2 байта […]