Skip to content

apmuthu/phpprojects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phpprojects - Ap.Muthu's PHP Snippets

List view
  • Aadhar - PHP Class, Non-Class and JS Validation of 12 digit Aadhar Number
  • AjaxDropDownSelect - Ajax and JS based cascading dropdown select box
  • AjaxRealTimeGraph - PHP based Real Time Plot of sensor values acquired using Ajax
  • phpDBF_Import.php - DBF to MySQL import - Schema and Data - using php-dbase extension
  • PHPFormToDBonce - One time update of record using random hash from a field in record
  • PHPProgressMonitor - Monitor progress of execution of a long running php script with examples
  • phpHitCounter - Implements a single webpage hit counter for a single file or set of files
  • SpriteCSSImages - Deploy several images from single Sprite Image using CSS. Use in counter digits display.
  • LangUtils - GetText manipulation scripts for rapid translations
  • LimeSurveyQAImport - SQLs generated to import List Radio Questions and Answers from Formatted Text file into LimeSurvey v2.051's DB
  • MSAccessInPHP/mdbtest.php - Illustrates the usage of MSAccess MDB file in PHP on Windows
  • OrangeHRMutils - External and internal bridges to OrangeHRM's Free Open Source Edition
  • PHPINICompare - Compare php.ini files across servers
  • phpRFT - PHP Remote File Transfer
  • phpTamilTabUniFont - Tamil TAB Font to Unicode and vice-versa functions
  • SubnetMaskcalc - Subnet Mask Calculator by subnetmask.info
  • translation - Easy PHP Site Translation class
  • unixtime/unix_time.html - Epoch Convertor from Online Conversion | Demo | Production
  • booklet-page-calculator.html - Booklet Page Calculator
  • cplusplus - C++ tutorial examples
  • clean_csv_quote_strings.php - Strips line feeds in quoted strings
  • data_in_php - Store, retrieve, include and execute data at the end of a php file
  • docgenerator - Generates a sample contractual agreement with data from a html form. Generate Disclaimer.
  • display_paged.php - Display a paged set of records from a MySQL table
  • domtute.php - PHP syntax for DOMDocument across PHP versions to treat searched objects as arrays
  • ipmon.php - Monitor status of devices using ping
  • jsDynaField - jQuery based Dynamic Form Field Addition
  • oct_repl.php - Octal to ASCII string replacer
  • opensslver.php - OpenSSL version checker - useful for checking if TLS alone is enabled
  • phpGetDomains - domain_lister.php - Get Insert SQL statements from registrar records at Daily Changes
  • php-mysql-functions - PHP functions for MySQL and Password set/blank bash scripts for MySQL 5.6
  • mssql_to_mysql.php - Converts CREATE TABLE and INSERT statements from MS SQL Server sql script to MySQL equivalents
  • php_recursive_menu.php - Assemble Menu Array from single MySQL query using recursive self lookup
  • phpCheckPAN.php - Indian Income Tax PAN card validity checker
  • phpDate2words.php - Convert Date string to proper cased words
  • phpssh2.php - PHP Tunnel into remote service on localhost
  • phpunzip - Unzip archives using php by PHPConcepts
  • php_wget.php - Use shell commands from within PHP (in windows too) and grab with wget
  • pincodes - Data Dump of Indian Postal Codes
  • wiki_extract.php - Extract urls of uploaded files in MediaWiki based Wikis and use with wget
  • sql2excel - php class to convert an sql to an excel worksheet
  • phpIMO_chkdigit.php - Generate IMO (shipping) check digit
  • phpLIKE.php - Unicode aware MySQL LIKE operator for PHP
  • phpLegacy.php - Backport of new PHP functions equivalents
  • unicode_sql2excel.php - Export SQL to Excel without any library (native CSV) for unicode data
  • gxlate - PHP Function for Google Translation of single string without using Google Translate API
  • cidr_match.php - Check if IPv4 is within subnet range and dynamically get a base URL
  • ip.php - Obtain your public / private ip
  • iprec.php - Store your public / private ip in a text file on the server and retrieve at will
  • ip2isp_tsv.php - Lookup the owner ISP of an array of IPs from https://ipinfo.io (free 1000 lookups per day per IP)
  • jsBase64Form.php - Submit a form field after base64 encoding it in javascript
  • perm.php - Set folders to 755 and files to 644 permissions recursively
  • PortReDirect.html - Redirects from Port 80 to any other port without port forwarding - plain HTML and JS only
  • UnixTS2DateTS.php - Convert Unix Timestamp to Readable Date Format in PHP
  • youtube_srt_corrector.php - Correct auto generated subtitles from YouTube Closed Captions
  • parse_apache2_log.sh - Parse Apache2 Log at /var/log/apache2/access.log
  • SetMTU.bat - When optical fibre length increases as occurs when re-routing on cut, latency increases - adjust Max Tx Unit
  • kill_wget.bat - Kill Windows Process when invoked from browser or other program like apache
pubip=`wget -qO- http://www.apmuthu.com/ip.php`
  • ascii_endecode.php - encrypt / decrypt ASCII code based index shift in php
  • DecryptCSinPHP.php - decrypt C# in php
  • xlate.php - Encode / Decode strings / binary in PHP
  • mod_rewrite_test.php - Advanced mod_rewrite troubleshooting tester
  • PHP_SourceCodeViewer.php - Place this file in a folder called source and name it index.php to view source code of all php files under it.
  • phpLuhn.php - generate and verify credit card checksums
  • var2file.php - Save a PHP variable in a file for including it in another PHP file.
  • AjaxJSselect.html - Javascript based drop down select controlled by another select box
  • TandC.php - Place defined constants in a PHP String
  • mask_download_url.php - Mask the real URL of a downloadable file in php

PDF Scripts

  • images_to_pdf.php - Join images in a folder into a single PDF file using FPDF library
  • pdfoverlay - Generate an overlaid PDF populating a template PDF file using data from a database
  • PDFMerger.php - Split and Merge PDF files using fpdf and fpdi
  • php_get_pdf_header.php - Extract Creation Date, Modified Date, Number of Pages and PDF Version from a PDF file

Page Generators

  • DMCA.php - Generate and/or use a DMCA page in your site

HowTo Articles

  • DOS_FileListInMySQL.md - Organise DOS File and Folder List into a MySQL table and generate Delete and Move commands

PHP CLI

  • php_is_cli.php - Checks if called from PHP CLI, obtains local server IP
  • php_cli_param_usage.php - Various ways to pass on parameters into a PHP script for CLI usage
  • php_cli_console_input.php - Get user input from console into PHP variable

Forex Parsers

  • dbs_xchg_rate.php - Get Exchange Rate from DBS Bank in Singapore Dollars
  • Bloomberg_Rates.php - Get currency exchange rate from Bloomberg
  • fxratenet_rates.php - Get currency exchange rate from fx-rate.net
  • XE/xe_xchg_rate.php - Get all From/To exchange rates from XE
  • x-rates/x-rates.php - Get 1 USD Exchange Rate of 53 Currencies from x-rates
  • rbi_inr_rates.php - Get latest Reserve Bank of India (RBI) Forex rates in INR

Format Parsers

  • EA_MSSQL_Parser - Enterprise Architect MS SQL Table format parse to MySQL table creation fragment
  • ExtractOptions.php - HTML select box options string to array
  • HTML2Links.php - Extract all unique filtered URLs with their display values from XML / HTML content
  • parse_word.php - Extract text from Word documents
  • ParseSQLstr.php - Parse SELECT columns of any SQL string without connecting to DB
  • xml2tsv - Convert XML to TSV (Tab Separated Values)
  • youtube2srt.php - Convert YouTube Transcript page text into subtitle .srt format
  • netgear_logs.sh - Netgear DG834G Router Log Parser
  • hierarchial_parser.php - Category, Sub-Category, Items parser from formatted text file
  • excel_parser_sample.php - Parse Excel data into PHP

Format Conversion

  • Debian to FreeBSD md5 format conversion and comparison in bash
# in Debian / Windows GitBash
find . -type f -exec md5sum '{}' \; > ../debian_md5.txt

# in FreeBSD
find . -type f -exec md5 '{}' \; > ../freebsd_md5.txt

awk -F'*' '{ print "MD5 ("$2") = "$1 }' ../debian_md5.txt  | sed 's/\s$//' > ../freebsd_formatted_md5.txt

diff ../freebsd_formatted_md5.txt ../freebsd_md5.txt

Windows CLI (From DOS Prompt)

7-Zip file extraction on desktop

"C:\Program Files\7-Zip\7z" e %USERPROFILE%\Desktop\content.epub -y -o%USERPROFILE%\Desktop\output *.pdf -r

Bash

Get External IP

curl -s ifconfig.me/ip # Using curl silently without progress bar
wget -qO- ifconfig.me/ip # Using wget quietly

Sort IPs

# Remove Comments and append new IPs and then:
grep -v "#" ip_blocked.txt | uniq | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n > ip_blocked_sorted.txt

Parse Apache2 access.log

cat /var/log/apache2/access.log | awk '{print $1}' | sort -nr | uniq -c | sort -nr | head -n 25

Watch clone (command here is ls -al)

while (true); do clear; ls -al; sleep 2; done

Remove delay in login for Debian (10.11.12) Buster, BullsEye and Bookworm LXC containers

systemctl mask systemd-logind

awk Remove duplicate lines

awk '!seen[$0]++'

awk Remove First and Last lines

awk executes the action print last only when NR > 2 (that is, on all lines but the first 2). On all lines, it sets the variable last to the current line. So when awk reads the third line, it prints line 2 (which was stored in last). When it reads the last line (line n) it prints the content of line n-1. The net effect is that lines 2 through n-1 are printed.

awk 'NR>2 {print last} {last=$0}'

awk Filter Unique lines without Sort

cat my_infile.txt | \
awk '!seen[$0]++' | \
awk '!seen[$0]++' > my_outfile.txt

paste Remove alternate new lines

cat my_infile.txt | \
paste - - > my_outfile.txt

unzip

find . -name "*.zip" | while read filename; do unzip -o -d "`basename "$filename" | cut -d"." -f1`" "$filename"; done;

extract unique IPv4 addresses from log.txt and store in new.txt

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' log.txt | sort -u > new.txt

Base64 encode all PNG and JPG files in Folder

find . -type f \( -name "*.png" -o -name "*.jpg" \) -exec bash -c 'base64 {} > {}.b64' \;
  • dd/mm/yyyy format to be reeplaced as yyyy-mm-dd format using RegEx Replace option
  • '11/04/2011', needs to become '2011-04-11'
  • Find: (\d+)/(\d+)/(\d{4}) Replace with: $3-$2-$1

Regex find line with missing string in Notepad++

  • Here the missing character is forward slash (/)
^((?!/).)*$

PHP

sed '${/?>/d;}' -i my_php_script.php
# Recursive within a folder:
cd /your/dir/here && find . -type f -print0 | xargs -0 sed -i '${/?>/d;}'

Debugging by append marker (AA here) to log file

$a = file_put_contents('./logs.txt', date('Y-m-d ')."AA".PHP_EOL , FILE_APPEND | LOCK_EX);

Check if string $a is unicode

if (strlen($a) != strlen(utf8_decode($a)))
	echo $a . " is unicode";

MySQL

get first 2 bytes of IPv4

INET_NTOA(INET_ATON( <IPField> ) & 0xFFFF0000)

move table

ALTER TABLE my_old_db.mytable RENAME my_new_db.mytable;

NULL / Zero (0) Substitutions

COALESCE( expression, 'a substitute for NULL' ) -- NULL only
COALESCE( NULLIF( expression, 0 ), 'a substitute for Zero' ) -- Zero only
IFNULL( NULLIF( expression, 0 ), 'a substitute for NULL or Zero') -- NULL or Zero

split email addresses

SELECT SUBSTR(MailID, 1, INSTR(MailID, '@') -1) FROM `users`; -- username
SELECT (SUBSTRING_INDEX(SUBSTR(MailID, INSTR(MailID, '@') +1),'.',1)) FROM `users`; -- domain first part
SELECT RIGHT(MailID, LENGTH(MailID)-INSTR(MailID, '@')) AS Domain FROM `users`; -- Full Domain only

Default CURRENT DATE for DEFAULT NULL date field dtable.query_date using trigger

USE `ddb`;
DELIMITER $$
CREATE TRIGGER `default_date` BEFORE INSERT ON `dtable` FOR EACH ROW
if ( isnull(new.query_date) ) then
 set new.query_date=curdate();
end if;
$$
delimiter ;

validate EMail addresses

SELECT * FROM tblExample
WHERE fldEMail IS NOT NULL 
  AND fldEMail NOT REGEXP '^[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9._+-]@[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]\\.[a-zA-Z]{2,63}$';

Extract Nth substring from string with delimiter

SET @N = 2; -- 2nd word
SET @haystack = '378459X293X4460'; -- example
SET @delimiter = 'X';
SELECT
  SUBSTRING_INDEX(SUBSTRING_INDEX(@haystack, @delimiter, @N), @delimiter, -1)
FROM
  my_table;

Windows GETMAC

getmac -v -fo list

DOS Unicode / UTF-8 file names

Change the code page at the DOS Prompt with:

chcp 65001

and then issue any command like:

dir /b > ..\files.txt
=TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
=RIGHT(A2,LEN(A2)-FIND("@",SUBSTITUTE(A2,"/","@",LEN(A2)-LEN(SUBSTITUTE(A2,"/",""))),1))

VLC Player CLI Merge MP3 files when in same format in windows

"%PROGRAMFILES%\VideoLAN\VLC\vlc.exe" -vv 1.mp3 2.mp3 3.mp3 --sout-keep --sout=#gather:transcode{acodec=mp3,ab=128}:standard{access=file,mux=dummy,dst=combinedout.mp3}

About

Ap.Muthu's PHP Repos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published