Posts

Showing posts from May, 2021

Make tar file exclude folder using command line

tar -czf backupname.tgz --exclude="/app/www/xyz" /app/www/

PHP - file mode permission

chmod("/dir/file.txt", 0755);

Linux command line search and replace string in all files

String Find and replace (folders/sub folders) > grep -rl "old string" . | xargs sed -i 's/old string/new string/g' URL Find and replace (folders/sub folders) > grep -rl "www\.google\.com" . | xargs sed -i 's/www\.google\.com/www\.yahoo\.com/g' Find string > grep -iRl "search string" /path/lcoation

PHP ERROR Reporting

ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

PHP - CURL POST

CURL POST $post_data_arr = [ 'f_name' => 'First', 'l_name' => 'Last', ]; $url = 'http://example.com'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data_arr); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); print_r($response); CURL POST with authentication $url = 'http://example.com'; $username = "username"; $password = "password"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 2); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data_arr); $response = curl_exec($curl); curl_close($curl); print_r($response);