terça-feira, 22 de março de 2011
domingo, 20 de março de 2011
Foreach
$nr_primos = explode(",","2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71");
foreach($nr_primos as $key => $value){
echo "key=" . $key . " - value=" . $value . "
";
}http://livrophp.com/
sábado, 19 de março de 2011
upload de imagens
function salva_banner($imagem,$pasta,$frase){
error_reporting(E_ALL);
include('class.upload.php');
$handle = new Upload($imagem);
$arquivo = isset($imagem) ? $imagem : FALSE;
if($arquivo){
$tamanhos = getimagesize($arquivo["tmp_name"]);
//echo "Aguarde, redimensionando sua imagem ...";
}
if ($handle->uploaded) {
// Configuracoes
$handle->file_overwrite = true;
$nome= md5(uniqid(time()));
$handle->file_new_name_body = $nome;
$handle->image_ratio = true;
if (($tamanhos[0] > 640) || ($tamanhos[1] > 480)) {
$escala = $tamanhos[0] / $tamanhos[1];
$tamanhow = 640;
$tamanhoh = 480;
$width = $tamanhos[0];
$height = $tamanhos[1];
if ($escala < 1.33333333333333333333){
$widthx = $tamanhoh * $escala;
$width = $widthx;
$height = $tamanhoh;
}elseif ($escala > 1.33333333333333333333){
$heightx = $tamanhow / $escala;
$width = $tamanhow;
$height = $heightx;
}else {
$heightx = $tamanhoh / $escala;
$width = $tamanhoh;
$height = $heightx;
}
$handle->image_resize = true;
$handle->image_x = $width;
$handle->image_y = $height;
}
else{
$handle->image_resize = false;
}
$handle->image_convert = 'jpg';
$handle->jpeg_quality = 60;
$handle->image_text = $frase;//'Teste ...'; //escreve um texto no meio da foto;
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process($pasta.'/'); //'fotos/');//pasta aonde vai ser guardado as fotos
return $pasta.'/'.$nome.'.jpg';
// we delete the temporary files
$handle-> Clean();
}
else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo '
';
}
}
error_reporting(E_ALL);
include('class.upload.php');
$handle = new Upload($imagem);
$arquivo = isset($imagem) ? $imagem : FALSE;
if($arquivo){
$tamanhos = getimagesize($arquivo["tmp_name"]);
//echo "Aguarde, redimensionando sua imagem ...";
}
if ($handle->uploaded) {
// Configuracoes
$handle->file_overwrite = true;
$nome= md5(uniqid(time()));
$handle->file_new_name_body = $nome;
$handle->image_ratio = true;
if (($tamanhos[0] > 640) || ($tamanhos[1] > 480)) {
$escala = $tamanhos[0] / $tamanhos[1];
$tamanhow = 640;
$tamanhoh = 480;
$width = $tamanhos[0];
$height = $tamanhos[1];
if ($escala < 1.33333333333333333333){
$widthx = $tamanhoh * $escala;
$width = $widthx;
$height = $tamanhoh;
}elseif ($escala > 1.33333333333333333333){
$heightx = $tamanhow / $escala;
$width = $tamanhow;
$height = $heightx;
}else {
$heightx = $tamanhoh / $escala;
$width = $tamanhoh;
$height = $heightx;
}
$handle->image_resize = true;
$handle->image_x = $width;
$handle->image_y = $height;
}
else{
$handle->image_resize = false;
}
$handle->image_convert = 'jpg';
$handle->jpeg_quality = 60;
$handle->image_text = $frase;//'Teste ...'; //escreve um texto no meio da foto;
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process($pasta.'/'); //'fotos/');//pasta aonde vai ser guardado as fotos
return $pasta.'/'.$nome.'.jpg';
// we delete the temporary files
$handle-> Clean();
}
else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo '
';
}
}
Pegar todos os nomes dos campos de uma tabela
$c=1;
while($c < mysql_num_fields($exec))
{echo mysql_field_name($exec, $c);
$c++;
}
?>
domingo, 13 de março de 2011
terça-feira, 8 de março de 2011
Função para criar insert
function insere($tabela,$nm_botao,$vl_botao){
$campos='';
$value='';
while (list ($key, $val) = each ($_POST))
{
if ($val)
{
$campos .= $key. ',';
$value .= "'".$val."'," ;
}
}
$campos_sql= explode(",$nm_botao",$campos);
$value_sql=explode(",'$vl_botao'",$value);
return "insert into $tabela ($campos_sql[0])values($value_sql[0]);";
}
?>
Operadores ternarios php
(Condição) ? (Código1) : (Código2);
exemplo
Observe o uso dos sinais ? e : para testar a condição. Se ela retornar um valor verdadeiro (true), Código1 será executado. Caso o retorno seja negativo (false), teremos a execução de Código2. Vejamos um exemplo prático:
$total = (24 / 8) * 2;
($total == 6) ? ($correto = true) : ($correto = false);
if($correto){
echo "O cálculo está correto.";
}
?>
http://www.arquivodecodigos.net/arquivo/tutoriais/php/curso_completo/parte_7/uso_do_operador_ternario_em_estruturas_condicionais.php
exemplo
Observe o uso dos sinais ? e : para testar a condição. Se ela retornar um valor verdadeiro (true), Código1 será executado. Caso o retorno seja negativo (false), teremos a execução de Código2. Vejamos um exemplo prático:
$total = (24 / 8) * 2;
($total == 6) ? ($correto = true) : ($correto = false);
if($correto){
echo "O cálculo está correto.";
}
?>
http://www.arquivodecodigos.net/arquivo/tutoriais/php/curso_completo/parte_7/uso_do_operador_ternario_em_estruturas_condicionais.php
terça-feira, 1 de março de 2011
usando foreach e usando list each
foreach($_POST as $campo=>$valor)
echo 'nome do campo '.$campo.' valor do campo '.$valor;
exibe nome do campo e o valor
ou
foreach($_POST as $ind=>$valor){
//echo $$ind = $valor. '
';
apenas o valor
}
.............................................................................
while (list ($key, $val) = each ($_POST))
{
if ($val){
echo $key;
echo '=';
echo $$key = $val;
echo '';
}
}
echo 'nome do campo '.$campo.' valor do campo '.$valor;
exibe nome do campo e o valor
ou
foreach($_POST as $ind=>$valor){
//echo $$ind = $valor. '
';
apenas o valor
}
.............................................................................
while (list ($key, $val) = each ($_POST))
{
if ($val){
echo $key;
echo '=';
echo $$key = $val;
echo '';
}
}
apenas os que contem valores
extract
extract($_POST);
// ou use: extract($_POST,EXTR_OVERWRITE)
insert into tabela (login, senha, email...) values ('$login', '$senha', '$email'...)
sendo que $login ou $senha são os nomes atribuídos ao inputs types do formulario como exemplo
http://garotosopa.wordpress.com/2009/05/30/7-coisas-simples-em-php-que-alguns-ainda-complicam/
// ou use: extract($_POST,EXTR_OVERWRITE)
insert into tabela (login, senha, email...) values ('$login', '$senha', '$email'...)
sendo que $login ou $senha são os nomes atribuídos ao inputs types do formulario como exemplo
http://garotosopa.wordpress.com/2009/05/30/7-coisas-simples-em-php-que-alguns-ainda-complicam/
Meu dreamwever cs3 deu appcrash
Após algum tempo programando o dream travava e era necessario reiniciar para continuar o trabalho
solução(traduzido do site http://kb2.adobe.com/cps/402/kb402776.html)
solução(traduzido do site http://kb2.adobe.com/cps/402/kb402776.html)
Solution
- Se Dreamweaver estiver aberto feche.
- Delete o arquivo WinFileCache-AD76BB20.dat from the Dreamweaver user configuration folder. Note that on Windows, the Application Data and AppData folders are hidden by default, so verify that your Windows Explorer folder options are set to View Hidden Folders. The location of this file is as follows:
- Dreamweaver CS3 on Windows Vista:
C:\Users\[username]\AppData\Roaming\Adobe\Dreamweaver 9\Configuration - Dreamweaver CS3 on Windows XP:
C:\Documents and Settings\[username]\Application Data\Adobe\Dreamweaver 9\Configuration
- Dreamweaver CS3 on Windows Vista:
- Restart Dreamweaver.
Assinar:
Postagens (Atom)