PHP va MySQL kodlarining qanday vazifalar bajarishi haqida to'liq yozib boramiz.
Bilganlarimizni qolganlar bilan baham ko'ramiz!
list($name, $surnane, $company)=split("|", "Sandjar | Alimov | BAT");
print "$name <br>";
print "$surname <br>";
print "$company <br>";$lottery=range(0, 9);$languag e=array("English", "Gealic", "Spanish");
$exist=in_array ("Spanish", $language); //bu yer da exist'ga TRUE ma'lumoti yoziladi.$great_wines=array("Autstr alia"=> "Clar endon Hills 96", "France"=> "Comte George de Vogue 97", "Austria"=> "Feiler Artinger 97");
$great_labels=array_keys($great_wines);$great_labels[0]=Australia
$great_labels[1]=F rance
$great_labels[2]=Austria<?
$languages=array("Uzbek", "Russian", "English");
array_push($languages, "French", "German");
foreach($languages as $item){
print "$item <BR>";
}
?>$languages=array("Uzbek", "Russian", "English");
$a_language=array_pop($languages); //a_language="English, languages="Uzbek", "Russian"$languages=array("French", "Russian", "German");
$a_lang=array_shift($languages); //a_lang="French"
array_unshift($languages, "Uzbek"); //languages="Uzbek", "Russian", "German"$weight=array(1 , 2, 3, 1 5, 35);
$weight=array_pad($weight, 8, 100);
//bu y erda biz uni hajmini 8 gacha oshirib, yangi yaratilgan hujralarga 100 sonini y ozib chiqishini belgiladik.
//$weight=1 , 2, 3, 1 5, 35, 100, 100, 100$weight=array(1 , 2, 3, 1 5, 35);
$weight=array_pad($weight, 8, 100);
//shu yerda biz $weight nin boshiga 100 raqamidan 3 donasini qo'shamiz, yanikim, weight'ning hajmini 8 oshiramiz, va faqat bosh jo ylarni weightning boshiga qoshib qo'yamiz. .gif)
$fruits=array("apple", "orange", "banana");
$a_fruits=reset($fruits); //a_fruits=apple$spices=array("parsley", "sage", "rosemary");
$a_spice=each($spices);
print "$a_spice[0] $a_spice[1] <br>";
$a_spice=each($spices);
print "$a_spice[0] $a_spice[1]";function delete_dupes($element){
static $last="";
if ($element==$last) {
unset($element);
}
$last=$element
}$emails=array("bom@bom.ru", "test@test.ru", "bom@bom.ru");
sort($emails);
reset($emails);
array_walk($emails, "delete_dupes");$machines=array("DONG", "Mitsubishi", "BMW");
$rev_machine=array_reverse($mac hine);
//rev_machine="BMW", "Mitsubishi", "DONG" kabi qiymatlarni oladi.$til=array("France"=>"French", "Uzbekistan"=>"Uzbek", "England"=>"English");
$tes_til=array_flip($til);
//shunda tes_til'ning qiymati quyidagicha bo'ladi tes_til="French"=>"France", "Uzbek"=>"Uzbekistan", "English"=>"England"$langs=array("English", "Russian", "Greec", "German");
$lang_size=sizeof($langs);
//lang_size=4$params=array("PA", "MA", "CA", "PA", "MO", "CA", "PA", "MA", "CO");
$params_c=array_count_values($params);
//params_c="PA"=>3, "MA"=>2, "CA"=2, "MO"=>1 , "CO"=>1 kabi qiyamtlarni oladi.$alfa=array("A", "C", "E", "D", "B");
sort($alfa);
//alfa="A", "B", "C", "D", "E"$cities=array("Tashkent", "Samarkand", "Andijan", "Qarshi");
asort($cities);cities[2]=Andijan
cities[1]=Samarkand
cities[0]=Tashkent
cities[4]=Qarshi$langs=array("France"=>"French", "England"=>"English", "Italy"=>"Spanish");
ksort($langs);$a1=array("a", "b", "c");
$a2=array("d", "e", "f");
$a3=array("g", "h", "i");
$ar4=array_merge($a1, $a2, $a3);
//ar4="a", "b", "c", ... "i" mana shu holga keladi, yani a1 , a2, a3 larni qo'shib qo'yadi.array array_slice(array masiv, int boshlanish, [int uzunligi]);array_splice(masiv, int boshlanish, [int uzunlik], [array o'zg artirish masivi]);$raqam = range(1, 20);
srand((float)microtime() * 1000000);
shuffle($raqam);
while (list(, $chiqar) = each($raqam)) {
echo "$chiqar ";
}<?php
$input = array("qizil", "yashil", "qora", "oq");
array_splice($input, 2);
// agarda $input 2 bo`lsa array("qizil", "yashil") chiqaradi
$input = array("qizil", "yashil", "qora", "oq");
array_splice($input, 1, -1);
// agarda $input 1, -1 bo`lsa array("qizil", "oq") chiqaradi
?>if(! file_exists($filename)):
print "File $filename does not exist!";
endif;$file = "test.txt";
if (is_file($file)):
print "The file $file is valid and exists!";
else:
print "The file $file does not exist or it is not a valid file!";
endif;$fs = filesize("pastry.txt");
print "Pastry.txt is $fs bytes.";$file = "userdata.txt";
$fh = fopen($file, "a+") or die ("File ($file) does not exist!");$file = "userdata.txt";
if (file_exists($file)):
$fh = fopen($file);
fclose($fh);
else:
print "File $file does not exist!";
endif;<?
$data = "08:13:00 | 12:37:12 | 208.247.106.87 | win98";
$filename = "test.txt";
if (is_writable($filename)):
$fh = fopen($filename, "a+");
$success = fwrite($fh, $data);
fclose($fh);
else:
print "Could not open $filename for writing";
endif;
?>$fh = fopen("pastry.txt", "r") or die ("Can't open file");
$file = fread($fh, filesize($fh));
print $file;
fclose($fh);$fh = fopen("pastry.txt", "r");
while(!feof($fh)):
$char = fgetc($fh);
print $char;
endwhile;
fclose($fh);$fh = fopen("pastry.txt", "r");
while (!feof($fh)):
$line = fgets($fh, 4096);
print $line;
endwhile;
fclose($fh);<?
file_array = file("pastry.txt");
while (list($line_num, $line) = each($file_array)):
print "$line_num: ", htmlspecialchars($line);
endwhile;
?><?
$file = "test.txt";
readfile($file);
?><?
$fh = fopen("test.txt", "w"); //test nomli fayl ochamiz
fputs($fh, "Salom Toshkent \n");
fputs($fh, "Bugun havo yaxshi \n");
fputs($fh, "Hayot gozal \n"); //faylning ichiga bir qancha ma'lumot yozamiz
fclose($fh); //faylni yopamiz
$fh = popen("grep Toshkent < test.txt", "r"); //Biz bu yerda Unix sistemasidagi grep buyrugini ishlatib test.txt faylidan Toshkent so'zini qidiradi va uni topgan qatori ekranga chiqaradi
fpassthru($fh); //ekranga chiqaramiz
?><?
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp){
echo "$errstr ($errno)<br>\n";
}
?><?
exec ("ping c 5 www.technoidea.boom.ru", $ping);
for ($i = 0; $i < count($ping); $i++):
print "<br>$ping[$i]";
endfor;
?>
00
00$output = 'ls';
print "<pre>$output</pre>";$user_in = 'rm rf *';
exec($user_in); //hafli hamma fayllar o'chib ketishi mumkindir.
$user_in = 'rm rf *';
exec(escapeshellcmd($user_in)); //hafli emas, sababi * belgisi olib tashlanadi$path = "/usr/local/sbin/skip.test";
$file = basename($path);echo "Last modified:", date("H:i:s a", getlastmod());$file = "datafile.txt";
list($dev, $inode, $inodep, $nlink$, $uid, $gid, $inodev, $size, $atime, $mtime, $ctime,
$bsize) = stat($file);
print "$file is $size bytes. <br>";
print "Last access time: $atime<br>";
print "Last modification time: $mtime <br>";$data_file = "data1.txt";
copy($data_file, $data_file'.bak.') or die ("Could not copy $data_file");$data_file = "data1.txt";
rename($data_file, $data_file'.old.') or die ("Could not rename $data_file");$path = "/usr/local/index.php";
$dirs = dirname($path);$file = "index.html";
$dirs = "/usr/local";
$isdir = is_dir($file); //isdir=FALSE
$isdir = is_dir($dirs); //isdir=TRUE$dh = opendir('.');
while ($file = readdir($dh)):
print "$file <br>"; endwhile;
closedir($dh);<?
$access = "hits.txt";
$visits = @file($access);
$current_visitors = $visits[0];
$all_me = (int)$current_visitors + 1;
$fh = fopen($access, "w");
$success = fwrite($fh, $all_me);
fclose($fh);
print "Visited: $all_me";
?><html>
<head>
<title> File Upload </title>
</head>
<body>
<h2> <b> Faylni tanlab yuklani bos </b></h2>
<form action="upload.php" method="post" enctype="multipart/formdata">
<input type="file" name="filename"><br>
<input type="submit" value="yukla"><br>
</form>
</body>
</html><html>
<head>
<title> Yuklandimi? </title>
</head>
<body>
<?php
if(copy($_FILES["filename"]["tmp_name"], "temp/".$_FILES["filename"]["name"])) {
echo("Fayl yuklandi");
} else {
echo("Fayl yuklana olmadi");
}
?>
</body>
</html><html>
<head>
<title> Fayl yuklandimi? </title>
</head>
<body>
<?php
if(copy($_FILES["filename"]["tmp_name"], "temp/".$_FILES["filename"]["name"])) {
echo("yuklandi <br>");
echo("Fayl bilan aloqali malumotlar: <br>");
echo("Ismi: " ) ;
echo($_FILES["filename"]["name"]) ;
echo("<br>Hajmi: ") ;
echo($_FILES["filename"]["size"]) ;
echo("<br>Yuklangan yeri: " ) ;
echo($_FILES["filename"]["tmp_name"]);
echo("<br>Fayl turi: " ) ;
echo($_FILES["filename"]["type"]);
} else {
echo("Yuklanmadi");
}
?>
</body>
</html>