Skip to content

Instantly share code, notes, and snippets.

View raihan-uddin's full-sized avatar
🎯
Focusing

Md. Raihan Uddin raihan-uddin

🎯
Focusing
View GitHub Profile
$fileName = 'Billing-Summary.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$fh = @fopen( 'php://output', 'w' );
<?php
$date1 = '2009-12-20 20:12:10';
$date2 = '2009-12-24 12:12:10';
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
echo floor($seconds_diff/3600/24);
<?php
array(
'name'=>'name',
'type'=>'raw',
'value'=>'$data->name',
'filter'=>$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$model,
'attribute'=>'name',
'source'=>$this->createUrl('user/usersAutoComplete'),
'options'=>array(
function GetBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
function extract_emails($str){
// This regular expression extracts all emails from a string:
$regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
preg_match_all($regexp, $str, $m);
return isset($m[0]) ? $m[0] : array();
}
$test_string = 'This is a test string...
function contains($str, $content, $ignorecase=true){
if ($ignorecase){
$str = strtolower($str);
$content = strtolower($content);
}
return strpos($content,$str) ? true : false;
}
@raihan-uddin
raihan-uddin / Parse CSV files
Created March 14, 2020 09:36 — forked from vrushank-snippets/Parse CSV files
PHP : Parse CSV files
$fh = fopen("contacts.csv", "r");
while($line = fgetcsv($fh, 1000, ",")) {
echo "Contact: {$line[1]}";
}
@raihan-uddin
raihan-uddin / Remove URLs from string
Created March 14, 2020 09:36 — forked from vrushank-snippets/Remove URLs from string
PHP : Remove URLs from string
$fh = fopen("contacts.csv", "r");
while($line = fgetcsv($fh, 1000, ",")) {
echo "Contact: {$line[1]}";
}
@raihan-uddin
raihan-uddin / read_files_from_dir.php
Created February 24, 2020 03:59 — forked from benedict-w/read_files_from_dir.php
PHP script to read files from a DIR parsing through a filename regex to match extensions
<?php
$files = array();
$folder = '../images';
$extensions = 'png';
if (is_dir($folder)){
$dir = opendir($folder);
while ($file = readdir($dir)) {
if (preg_match("/^[^\.].+\.{$extensions}$/i", $file)) {