marrtins Posted February 9, 2011 Report Share Posted February 9, 2011 He, tas getTimezoneIdentifierByCoordinates ir tieši kas man pēc dažām dienām būs vajadzīgs :)) Patestēsim. Quote Link to comment Share on other sites More sharing options...
Kracker Posted January 9, 2012 Report Share Posted January 9, 2012 Funkcija priekš paroles ģenerēšanas function parole($garums= 7) { $aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9)); $izvade =''; for($c=0;$c < $garums;$c++) { $izvade .= $aZ09[mt_rand(0,count($aZ09)-1)]; } return $izvade; } Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted January 10, 2012 Report Share Posted January 10, 2012 (edited) Nav labākais risinājums, jo useri nevar atšķirt I no l ( pats vari ? ) piemēram atnāks tev parole: IlIlIlIl tagat ludzu ievadi ;) (tur ir gan lielais i gan mazais L ) piedevam labak visus ar lielajiem vai visus ar mazajiem. tāpēc jaizvairās no simboliem kuri var izraisīt pārpratumus i L 1 0 o Zinu šo no pieredzes. function paroles_generators($length) { $keychars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; $randkey = ""; $max=strlen($keychars)-1; for ($i=0;$i<=$length;$i++) { $randkey .= substr($keychars, rand(0, $max), 1); } return $randkey; } P.S. ka to masīvu izvadi jau vairs nav būtiski , doma bija tieši par masīva saturu . edit: nu jā var vel piemest spec simbolus @ # $ % & * Edited January 10, 2012 by Grey_Wolf Quote Link to comment Share on other sites More sharing options...
Kavacky Posted January 10, 2012 Report Share Posted January 10, 2012 Paroles vispār nevajag ģenerēt. Quote Link to comment Share on other sites More sharing options...
Nils Graustiņš Posted February 12, 2012 Report Share Posted February 12, 2012 Funkcija, ja masīvs ir jāattēlo kā seletBox Funkcija lang() ir valodas funkcija un tās realizācija ir cits stāsts. function lang($x){ return ('['.$x.']'); } function select($array,$name,$value,$js=''){ $return= '<code>'.lang($name).'</code>'; $return.="\n".'<select name="'.$name.'" '.$js.'>'; foreach (array_keys($array) as $key){ $sel = $value == $key ? ' selected ':''; $return.="\n".'<option '.$sel.' value="'.$key.'">'.lang($array[$key]).'</option>'; } $return.="\n".'</select>'; return $return; } echo select($years=array(2011,2012,2013),'car[year_of_manufactoring]',2012,$js=''); Quote Link to comment Share on other sites More sharing options...
Nils Graustiņš Posted February 12, 2012 Report Share Posted February 12, 2012 Mūžam vecā undefined problēma ar GET un POST function get($key,$default=false){ return isset($_GET[$key])?$_GET[$key]:$default; return $return; } function post($key,$default=false){ return isset($_POST[$key])?$_POST[$key]:$default; } Quote Link to comment Share on other sites More sharing options...
Nils Graustiņš Posted February 12, 2012 Report Share Posted February 12, 2012 Funkcija čekboxu atgriešanai no mysql tabulas ( ja to ir mazāk par 100 :) ) function checkBoxList($name,$idx,$table,$values,$rule=null){ #RETURNS: # array('column<checkBox name="table[keyrow]" value="1"/>', ...) $q=' SELECT '.$name.','.$idx.' FROM '.$table.' '; if( is_string($rule) ) { $q.=' WHERE '.$rule.' ';} if( is_array($rule) ) { $q.=' WHERE '. implode(' AND ',$rule);} $result = mysql_query($q); if( !$result ) { return mysql_error().'@'.__LINE__.__FILE__; } $return =array(); while( $row = mysql_fetch_row($result)) { $sel=''; if(is_array($values)){if(in_array($row[1],$values)){$sel='checked';}}else{ if($row[1]===$values) {$sel='checked';}} $return[] = $row[0].'<input type="checkbox" name="'.$table.'['.$row[1].']" '.$sel.' value="1"/>'; } return $return; } Lietojums: $list= checkBoxList('user','id','users', $values=array(4,5),$rule='active=1'); echo implode('<hr/>',$list) Quote Link to comment Share on other sites More sharing options...
codez Posted February 12, 2012 Report Share Posted February 12, 2012 Abstrakcija, abstrakcija, abstrakcija,... Ja es gribu uzģenerēt checkboxu no memcached datiem, vai no cita avoda, tad man šī funkcija ir nederīga, jo tā satur 2 pilnīgi dažādas funkcionalitātes: 1) nolasīt datus no mysql, 2)no datiem uzbūvēt checkboxa html. Tik atšķirīgām funkcionalitātēm jāatrodas atsevišķi. Quote Link to comment Share on other sites More sharing options...
Nils Graustiņš Posted February 12, 2012 Report Share Posted February 12, 2012 Vai šādi nav vienkāršāk? //Iegūstam faila paplašinājumu function getFileExtension($file_name){ return end explode('.',$file_name); } } Quote Link to comment Share on other sites More sharing options...
Val Posted March 17, 2012 Report Share Posted March 17, 2012 function seo_string($str, $separator = '-') { setlocale(LC_ALL, 'en_US.UTF8'); return str_replace(' ', $separator, trim(preg_replace('/[^ A-Za-z0-9_]/', ' ', trim(iconv('UTF-8', 'ASCII//TRANSLIT', preg_replace('/[ -]+/', '-', $str)))))); } Šeit vēl prasās preg_replace('/--+/', '-', $str), lai vairākas viena otrai sekojošas domuzīmes aizvietotu ar vienu. Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted August 14, 2013 Report Share Posted August 14, 2013 (edited) Mūžu senā bet noderīgā funkcija array apskatei normālā skatā ar <pre> tagiem. function printr($var){ echo "<pre>"; print_r($var); echo "</pre>"; } Kā arī kautkas prieciņam :) function skaitamAitas($aitas){ $i = 1; while ( $i <=$aitas ) { echo $i++ .'. aita<br>'; } } Edited August 14, 2013 by Pieduriens Quote Link to comment Share on other sites More sharing options...
marrtins Posted August 14, 2013 Report Share Posted August 14, 2013 (edited) function printr($var){Hei, no manis nozagi? Edited August 14, 2013 by marrtins Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted August 14, 2013 Report Share Posted August 14, 2013 Hei, no manis nozagi? Hei, nē, pats izdomāju, lai gan tas ir tik universāli, ka domājams te nav ko zagt..divriteni no jauna neizgudrosi, bet ikdienā viena no top funkcijām.. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted August 15, 2013 Report Share Posted August 15, 2013 Tu tā ikdienā debago kodu? I feel sorry for you... Quote Link to comment Share on other sites More sharing options...
daGrevis Posted August 15, 2013 Report Share Posted August 15, 2013 ^ WTF. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.