zxz |
20.02.2011 02:04 |
Predmet:Koristan PHP kod
U ovoj temi se nalazi koristan PHP kod.
Obavezno staviti naslov za svaki post. |
zxz |
12.03.2011 14:09 |
Predmet:Slanje emaila
Slanje emaila
PreuzmiIzvorni kôd (PHP):function genSendEmail($to, $subject, $moja_poruka, $from_address="admin@programeri.com", $from_name="Moke") {
$message = "<html><head>
<title>".$subject."</title>
</head>
<body>
".$moja_poruka."
</body>
</html>
";
// Da bi poslali HTML email, the Content-type mora biti podesen
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Dodatni headers
$headers .= 'To: '.$to.' <'.$to.'>' . "\r\n";
$headers .= 'From: '.$from_name.' <'.$from_address.'>' . "\r\n";
// -- Posalji postu
ini_set(sendmail_from ,$from_address); // INI configuracija, prisili FROM adresu
$mail_sent = mail($to, $subject, $message, $headers);
return $mail_sent;
}
|
zxz |
12.03.2011 14:12 |
Predmet:Redirect
Procedura vrsi redirekciju.
PreuzmiIzvorni kôd (PHP):<?php
function genRedirect( $url, $msg='' ) {
// Izbrisi sve sto nam nije potrebno
$url = $url[0];
}
echo "<script>document.location.href='$url';</script>\n";
} else {
header( 'HTTP/1.1 301 Moved Permanently' );
}
}
?>
|
zxz |
04.03.2012 02:08 |
Predmet:Upload fajla
Ovo kopirajte u fal i dajte mu ime upload.html
PreuzmiIzvorni kôd (HTML):
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
Ovaj kod kopirajte i zapisite u isti dir kao i predhodni i dajte mu ime upload_file.php
PreuzmiIzvorni kôd (PHP):<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
|
zxz |
05.03.2012 21:24 |
Predmet:Kako otvoriti txt file
PreuzmiIzvorni kôd (HTML):
<?php
$file=fopen("welcome.txt","r");
?>
Opcije:
Modes | Description |
---|
r | Read only. Starts at the beginning of the file | r+ | Read/Write. Starts at the beginning of the file | w | Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist | w+ | Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist | a | Append. Opens and writes to the end of the file or creates a new file if it doesn't exist | a+ | Read/Append. Preserves file content by writing to the end of the file | x | Write only. Creates a new file. Returns FALSE and an error if file already exists | x+ | Read/Write. Creates a new file. Returns FALSE and an error if file already exists | Sljedeći primjer generira poruku ako fopen () funkcija nije u mogućnosti da biste otvorili navedenu datoteku:
PreuzmiIzvorni kôd (HTML):
<?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
?>
Fclose () funkcija koristi se da biste zatvorili otvorenu datoteku:
Primjer:
PreuzmiIzvorni kôd (PHP):<?php
$file = fopen("test.txt","r");
//some code to be executed
?>
|
zxz |
09.11.2013 22:03 |
Predmet:Primjer switch
PreuzmiIzvorni kôd (PHP):<?php
$favcolor="red";
switch ($favcolor)
{
case "red":
echo "Boja je red!";
break;
case "blue":
echo "Boja je blue!";
break;
case "green":
echo "Boja je green!";
break;
default:
echo "Moji favoriti boja su red, blue, or green!";
}
?>
|
zxz |
03.11.2016 10:33 |
Predmet:Foreach primjer
Primjer iscitavanja iz Array:
PreuzmiIzvorni kôd (HTML):<!DOCTYPE html>
<?php
$imena = array("Enes"=>"35", "Marko"=>"40", "Ivan"=>"43","mujo"=>"60");
foreach($imena as $ime => $godine)
{
echo $ime . ":" . $godine . "god.";
}
?>
Ovdje se moze upotrijebiti i funkcija sort, rsort, arsort itd...
PreuzmiIzvorni kôd (HTML):<!DOCTYPE html>
<?php
$vocke = array ("jabuka", "banana", "ananas", "kruška", "šljiva","smokva");
sort($vocke);
foreach ( $vocke as $vocka )
{
echo "$vocka<br />";
}
?>
|
zxz |
05.11.2016 18:10 |
Predmet:Globalne variable
Primjer globalnih variabli.
PreuzmiIzvorni kôd (HTML):
<META NAME="generator" CONTENT="toniarts easyhtml v.2.4">
<?php
$a = 120;
$b = 180;
function globalvar() {
$GLOBALS['c'] = $GLOBALS['a']+$GLOBALS['b'];
}
globalvar();
echo $c;
?>
|
zxz |
06.11.2016 12:28 |
Predmet:Sort primjer
Sortiranje po abecedno redu od a doZ.
PreuzmiIzvorni kôd (HTML):<!DOCTYPE html>
<?php
$imena = array("Ivo", "Bono", "Jakub","Enes","Azra","Vinko","Zoran","Mujo");
sort($imena);
$brimena = count($imena);
for($x = 0; $x < $brimena; $x++) {
echo $imena[$x];
echo "<br>";
}
?>
Ako upotrijebimo komandu rsort umjesto sort dobit cemo sortiranje od z do a.
Isto vazi i za brojeve.
Postoje jos i komande:
asort
ksort
krsort
arsort
PreuzmiIzvorni kôd (HTML):<!DOCTYPE html>
<?php
$imena = array("Ivo"=>"32", "Bono"=>"24", "Jakub"=>"56","Enes"=>"18","Azra"=>"19","Vinko"=>"30","Zoran"=>"65","Mujo"=>"35");
asort($imena);
$brimena = count($imena);
foreach($imena as $imeo=>$starost)
{
echo $imeo . " :" . $starost . " godina";
}
?>
|
zxz |
19.07.2018 11:40 |
Predmet:Broj slovima
Cesto trazena procedura ispisivanje broja tekstom.
Procedure su u klsi.
Poziva se napr:
require_once("classes/class.brslovima.php");
$imevariable = new br_slova();
Ukoliko nekome treba u nekom drugom programskom jeziku moze se prevesti.
Uvijek je ideja naj bitnija. |
Prilozi: class.brslovima.zip (Velicina datoteke:1.24 KB)
|