Skip to content

Instantly share code, notes, and snippets.

View rajvanshipradeep15's full-sized avatar

Pradeep Rajvanshi rajvanshipradeep15

  • India
View GitHub Profile
@rajvanshipradeep15
rajvanshipradeep15 / get integer from string
Created September 19, 2013 10:18
get integer from string
http://stackoverflow.com/questions/6278296/extract-numbers-from-a-string
// to get integer from string
preg_match_all('!\d+!', $string, $matches);
print_r($matches);
@rajvanshipradeep15
rajvanshipradeep15 / detect end of scroll in div
Created September 18, 2013 09:33
Detect end of scroll in a div
<style type="text/css">
div.scroll
{
width:500px;
height:400px;
overflow:scroll;
}
</style>
<div class="scroll">
some text is present
@rajvanshipradeep15
rajvanshipradeep15 / checkbox code
Created September 8, 2013 15:07
php checkboxes code
$('#' + id).is(":checked")
that gets if the checkbox is checked.
for an array of checkboxes with the same name you can get the list of checked ones by
var boxes = $('input[name=thename]:checked');
then to loop through them and see what's checked you can do
echo JHTML::_('calendar','value', 'start', 'id', $format = '%d-%m-%Y', array('class'=>'inputbox', 'size'=>'25', 'maxlength'=>'19'));
$db =& JFactory::getDBO();
$db->setQuery( $query );
$db->query();
To get the last insert id:
$db->insertid();
To get Number of rows fetched
$db->getNumRows();
@rajvanshipradeep15
rajvanshipradeep15 / zipfile upload
Created August 19, 2013 07:20
upload a zip file and unzip inserver
if($_FILES["zip_file"]["name"]) {
$filename = $_FILES["zip_file"]["name"];
$source = $_FILES["zip_file"]["tmp_name"];
$type = $_FILES["zip_file"]["type"];
$name = explode(".", $filename);
$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
foreach($accepted_types as $mime_type) {
if($mime_type == $type) {
$okay = true;
break;
// to calculate age
$interval = date_diff(date_create(), date_create('2008-01-01 10:30:00'));
echo $interval->format("You are %Y Year, %M Months, %d Days, %H Hours, %i Minutes, %s Seconds Old");
About Date
/* $startYear=strtotime(date("Y-04-1"));
$startYear = date('Y-m-d', $startYear);
// echo "startyear : ". $startYear;
// $startYear = DateTime::createFromFormat('Y-m-d', $startYear);
@rajvanshipradeep15
rajvanshipradeep15 / countrycodes
Created June 17, 2013 08:28
Country codes: countrycodes
$country_array = array(
"AA" => "Please select country",
"AFG" => "Afghanistan" ,
"ALB" => "Albania" ,
"DZA" => "Algeria" ,
"ASM" => "American Samoa" ,
"AND" => "Andorra" ,
"AGO" => "Angola" ,
"AIA" => "Anguilla" ,
"ATA" => "Antarctica" ,
@rajvanshipradeep15
rajvanshipradeep15 / gist:5705284
Created June 4, 2013 11:34
php : importing csv file to mysql
<?php
/*$connect = mysql_connect('localhost','root','12345');
if (!$connect) {
die('Could not connect to MySQL: ' . mysql_error());
}*/
// $cid =mysql_select_db('test',$connect);
// supply your database name
@rajvanshipradeep15
rajvanshipradeep15 / gist:5696434
Created June 3, 2013 06:36
joomla: include jfactory class in external php file
Include Jfactory class in external php file
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] );
... then you need to include three files, like:
require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );