nedir

<?
$arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png");
echo "Standard string comparison
";
usort($arr1,"strcmp");
print_r($arr1);
echo "
Natural order string comparison
";
usort($arr2,"strnatcmp");
print_r($arr2);
?>

kaynak: ordan burdan

<?
class search_replace{

var $find;
var $replace;
var $files;
var $directories;
var $include_subdir;
var $ignore_lines;
var $ignore_sep;
var $occurences;
var $search_function;
var $last_error;

/**
** Constructor function. Sets up the
** above functions.
**/
function search_replace($find, $replace, $files, $directories = '', $include_subdir = 1, $ignore_lines = array()){

$this->find = $find;
$this->replace = $replace;
$this->files = $files;
$this->directories = $directories;
$this->include_subdir = $include_subdir;
$this->ignore_lines = $ignore_lines;

$this->occurences = 0;
$this->search_function = 'search';
$this->last_error = '';

}

/*
** Accessor for retrieving occurences.
**/
function get_num_occurences(){
return $this->occurences;
}

/*
** Accessor for retrieving last error.
*/
function get_last_error(){
return $this->last_error;
}

/*
** Accessor for setting find variable.
*/
function set_find($find){
$this->find = $find;
}

/*
** Accessor for setting replace variable.
*/
function set_replace($replace){
$this->replace = $replace;
}

/*
** Accessor for setting files variable.
*/
function set_files($files){
$this->files = $files;
}

/*
** Accessor for setting directories variable.
*/
function set_directories($directories){
$this->directories = $directories;
}

/*
** Accessor for setting include_subdir variable.
*/
function set_include_subdir($include_subdir){
$this->include_subdir = $include_subdir;
}

/**
** Accessor for setting ignore_lines variable.
*/
function set_ignore_lines($ignore_lines){
$this->ignore_lines = $ignore_lines;
}

/*
** Function to determine which search
** function is used.
*/
function set_search_function($search_function){
switch($search_function){
case 'normal': $this->search_function = 'search';
return TRUE;
break;

case 'quick' : $this->search_function = 'quick_search';
return TRUE;
break;

case 'preg' : $this->search_function = 'preg_search';
return TRUE;
break;

case 'ereg' : $this->search_function = 'ereg_search';
return TRUE;
break;

default : $this->last_error = 'Invalid search function specified';
return FALSE;
break;
}
}

/*
** The main search and replace routine.
** Private function - DO NOT CALL!
*/
function search($filename){

$occurences = 0;
$file_array = file($filename);

for($i=0; $i<count($file_array); $i++){

if(count($this->ignore_lines) > 0){
for($j=0; $j<count($this->ignore_lines); $j++){
if(substr($file_array[$i],0,strlen($this->ignore_lines[$j])) == $this->ignore_lines[$j]) continue 2;
}
}

$occurences += count(explode($this->find, $file_array[$i])) - 1;
$file_array[$i] = str_replace($this->find, $this->replace, $file_array[$i]);
}
if($occurences > 0) $return = array($occurences, implode('', $file_array)); else $return = FALSE;
return $return;

}

/*
** The quick search function. Does not
** support the ignore_lines feature.
*/
function quick_search($filename){

clearstatcache();

$file = fread($fp = fopen($filename, 'r'), filesize($filename)); fclose($fp);
$occurences = count(explode($this->find, $file)) - 1;
$file = str_replace($this->find, $this->replace, $file);

if($occurences > 0) $return = array($occurences, $file); else $return = FALSE;
return $return;

}

/*
** The preg search function. Does not
** support the ignore_lines feature.
*/
function preg_search($filename){

clearstatcache();

$file = fread($fp = fopen($filename, 'r'), filesize($filename)); fclose($fp);
$occurences = count($matches = preg_split($this->find, $file)) - 1;
$file = preg_replace($this->find, $this->replace, $file);

if($occurences > 0) $return = array($occurences, $file); else $return = FALSE;
return $return;

}

/*
** The ereg search function. Does not
** support the ignore_lines feature.
*/
function ereg_search($filename){

clearstatcache();

$file = fread($fp = fopen($filename, 'r'), filesize($filename)); fclose($fp);

$occurences = count($matches = split($this->find, $file)) -1;
$file = ereg_replace($this->find, $this->replace, $file);

if($occurences > 0) $return = array($occurences, $file); else $return = FALSE;
return $return;

}

/*
** Function for writing out a new file.
*/
function writeout($filename, $contents){

if($fp = @fopen($filename, 'w')){
flock($fp,2);
fwrite($fp, $contents);
flock($fp,3);
fclose($fp);
}else{
$this->last_error = 'Could not open file: '.$filename;
}

}

/*
** Internal function called by do_search()
** to sort out any files that need searching.
*/
function do_files($ser_func){
if(!is_array($this->files)) $this->files = explode(',', $this->files);
for($i=0; $i<count($this->files); $i++){
if($this->files[$i] == '.' OR $this->files[$i] == '..') continue;
if(is_dir($this->files[$i]) == TRUE) continue;
$newfile = $this->$ser_func($this->files[$i]);
if(is_array($newfile) == TRUE){
$this->writeout($this->files[$i], $newfile[1]);
$this->occurences += $newfile[0];
}
}
}

/*
** Internal function called by do_search()
** to sort out any dirs that need searching.
*/
function do_directories($ser_func){
if(!is_array($this->directories)) $this->directories = explode(',', $this->directories);
for($i=0; $i<count($this->directories); $i++){
$dh = opendir($this->directories[$i]);
while($file = readdir($dh)){
if($file == '.' OR $file == '..') continue;

if(is_dir($this->directories[$i].$file) == TRUE){
if($this->include_subdir == 1){
$this->directories[] = $this->directories[$i].$file.'/';
continue;
}else{
continue;
}
}

$newfile = $this->$ser_func($this->directories[$i].$file);
if(is_array($newfile) == TRUE){
$this->writeout($this->directories[$i].$file, $newfile[1]);
$this->occurences += $newfile[0];
}
}
}
}

/**
** This starts the search/replace off.
** Call this to do the search.
** First do whatever files are specified,
** and/or if directories are specified,
** do those too.
*/
function do_search(){
if($this->find != ''){
if((is_array($this->files) AND count($this->files) > 0) OR $this->files != '') $this->do_files($this->search_function);
if($this->directories != '') $this->do_directories($this->search_function);
}
}

} // End of class
?>

<?

include('class.search_replace.inc');

/*
** Create the object, set the search
** function and run it. Then change the
** pattern to find something else, and
** re-run the search.
*/

$sr = new file_search_replace('test', 'Replaced!', array('test.txt'), '', 1, array('##'));

/**
** Following function not necessary as
** normal is the default, but here to
** illustrate it.
*/
$sr->set_search_function('normal');

$sr->do_search();
$sr->set_find('another');
$sr->do_search();

/*
** Some ouput purely for the example.
*/
header('Content-Type: text/plain');
echo 'Number of occurences found: '.$sr->get_num_occurences()."
";
echo 'Error message………….: '.$sr->get_last_error()."
";

?>

kaynak: ordan burdan

<?
$row = 1;
$handle = fopen ("dosya.csv","r");
while ($veri = fgetcsv ($handle, 1000, ",")) {
$no = count ($veri);
print "<p> $no fields in line $row: <br>
";
$row ;
for ($c=0; $c < $no; $c ) {
print $veri[$c] . "<br>
";
}
}
fclose ($handle);
?>

kaynak: ordan burdan

<?
$lines = file ('http://www.otelreferans.com/');

foreach ($lines as $line_num => $line) {
echo "{$line_num} - satır</b> : " . htmlspecialchars($line) . "<br>
";
}
?>

kaynak: ordan burdan

<?

foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "<br>";
}

?>

kaynak: ordan burdan

<?

$path_parts = pathinfo("/www/htdocs/index.");

echo $path_parts["dirname"] . "
"; //klasor yol adı
echo $path_parts["basename"] . "
"; //dosya tam adı
echo $path_parts["extension"] . "
"; //dosya uzantısı

?>

kaynak: ordan burdan

<?
$dosyaadi = 'dosya.txt';

if (file_exists($dosyaadi)) {
print "Dosya Bulunamadı";
} else {
print "Dosya Var";
}
?>

kaynak: ordan burdan

<?

$imgfolder = "images/mini";

// Checks if the file is an image. If not, it won't be added to the image list
function is_image($filename){
$filename = strtolower($filename) ;
$ext = split("[/\.]", $filename) ;
$n = count($ext)-1;
$ext = $ext[$n];

// Here you can list the extensions you want to be allowed
if($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG" || $ext == "gif" || $ext == "GIF" || $ext == "png" || $ext == "PNG") {
return true;
} else {
return false;
}
}

// Read the image folder into an array
$dir = opendir($imgfolder);
$array = array();
// Run through the folder
while($file = readdir($dir)) {
// Checks if the file is an image. Check the is_image() function a but up in this file
if(is_image($file)) {
// It's an image!! Put it into the array
array_push($array, $file);
}
}

// Count the amount of images in the array
$count = (count($array)-1);

// Generate a random number
$rand = rand(0,$count);

// Select an image from the array based on the random number
$img = $array[$rand];

// Output the image
echo '<img src="'.$imgfolder.'/'.$img.'" border="1">';
?>

kaynak: ordan burdan

<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/; charset=utf-8" />
<title>Multi-Checkbox Checker</title>
<script language="">
function getElement(e){
if(document.getElementById(e)){ var obj = document.getElementById(e);
}else if(document.getElementsByName(e)){ var obj = document.getElementsByName(e);
}else if(document.all){ var obj = document.all[e];
}else{ return false; }
return obj;
}
var checked = false;
function multi_check(, me){
/// = id
/// me = toggler id (optional)
var = elements = document.forms[];
if( == null || == 'undefined'){ return false; }
elements = .elements;
///->
var found = false;
var chk_box = new Array();
var unchk_box = new Array();
var chk_num = 0;
var unchk_num = 0;
///->
var me_found = false;
var its_me = '';
if(me != null && me != 'undefined'){ var find_me = true; }else{ var find_me = false; }
///->
for(var i = 0; i < elements.length; i++){
if(elements[i].type == 'checkbox' && elements[i].name != me){
found = true;
if(elements[i].checked){ chk_box[chk_num] = elements[i]; chk_num++;
}else{ unchk_box[unchk_num] = elements[i]; unchk_num++; }
}else if(elements[i].name == me && find_me){
if(elements[i].type == 'checkbox'){ its_me = elements[i]; me_found = true;
}else{ find_me = false; me_found = false; }
}
}
///->
if(!me_found){ if(getElement(me)){ me_found = true; its_me = getElement(me); } }
if(!found){ return false; }
if(unchk_num == 0){ checked = true; }
if(checked && find_me && me_found){ its_me.checked = false; }
///->
if(unchk_box.length && !checked){
for(var un = 0; un < unchk_box.length; un++){
unchk_box[un].checked = true;
}
checked = true;
}else{
for(var ch = 0; ch < chk_box.length; ch++){
if(checked){ chk_box[ch].checked = false; }
}
checked = false;
}
return false;
}
</script>
</head>

<body>
< action="#" id="cc">
<a href="#" onclick="multi_check('cc'); return false;">Check/Uncheck All</a>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</>
</body>
</>

kaynak: ordan burdan

<><head><title>rancolor</title></head>
<body>
<?
function randColor()
{
$letters = "1234567890ABCDEF";
for($i=0;$i<6;$i++)
{
$pos = rand(0,15);
$str .= $letters[$pos];
}
return "#".$str;
}
for($i=1;$i<6;$i++)
{
echo '<span style="color:'.randColor().'">Random Color Text</span><BR>';
}
?>
</body></>

kaynak: ordan burdan

Bence süper bir kod
Bende yeni öğrendim gerçi çok lazım olmadıydı.
Ama öğrenirseniz mutlaka kullanacağınız yer vardır

Böyyük Patron eder.

<?
${'c'.'o'.'d'.'e'.'k'.'o'.'d'.'u'} = 'En büyük Yardımcınız www.codekodu.com';

echo ${'c'.'o'.'d'.'e'.'k'.'o'.'d'.'u'}."<br>";

${substr('codekodu', 0, 4)} = 'hadi sizde www.codekodu.com a kod ekleyin';

echo ${substr('codekodu', 0, 4)}."<br>";

${ 'a' == 'b' ? 'rts' : 'str' } = 'www.codekodu.com ticari amacı olmayan bilgi paylaşım merkezi';

echo ${ 'a' == 'b' ? 'rts' : 'str' };

?>

kaynak: ordan burdan

<?
$dosyaadi = 'heryerdentatil.gif';

// 1.yol
$uzanti = end(explode('.', $dosyaadi));

echo $uzanti."<br>";

// 2.yol
$uzanti = substr(strrchr($dosyaadi, '.'), 1);

echo $uzanti."<br>";

// 3.yol
$uzanti = substr($dosyaadi, strrpos($dosyaadi, '.') + 1);

echo $uzanti."<br>";

// 4.yol
$uzanti = preg_replace('/^.*.([^.]+)$/D', '$1', $dosyaadi);

echo $uzanti."<br>";

// 5.yol

$uzantis = split("[/\.]", $dosyaadi);
$n = count($uzantis)-1;
$uzanti = $uzantis[$n];

echo $uzanti;
?>

kaynak: ordan burdan

link exchange yani link değişimi yaptığınız sizin linkinizi hala gösteriyormu,yoksa linki kaldırmışmı ?
Bu kontrolü aşağıdaki fonksiyonla yapabilirsiniz

<?
function check_back_link($remote_url, $your_link) {
$match_pattern = preg_quote(rtrim($your_link, "/"), "/");
$found = false;
if ($handle = @fopen($remote_url, "r")) {
while (!feof($handle)) {
$part = fread($handle, 1024);
if (preg_match("/<a(.*)href=["']".$match_pattern."(/?)["'](.*)>(.*)</a>/", $part)) {
$found = true;
break;
}
}
fclose($handle);
}
return $found;
}
// örnek:
//if (check_back_link("http://www.hedefsite.com", "http://www.siteniz.com")) echo "Link bulundu.";
?>

kaynak: ordan burdan

<?
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);

$ping_ip_addr = $_POST['ping_ip_addr']; // input
$ping_count = $_POST['ping_count']; // select

if (get_magic_quotes_gpc())
{
$ping_ip_addr = stripslashes($ping_ip_addr);
}

$ping_count_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25);
?>
< xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ping</title>
<meta http-equiv="Content-Type" content="text/; charset=iso-8859-9" />
<meta name="author" content="firstbase" />
<style type="text/css">
div.output {
margin:0; padding:10px; background-color:#eeeeee; border-style:solid; border-width:1px; border-color:#000000; }

body {
margin:0; padding:10px; background-color:#ffffff; }
</style>
</head>
<body>
<h1>Ping Atma</h1>
< action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><label for="ping_ip_addr">IP :</label><br />
<input name="ping_ip_addr" id="ping_ip_addr" type="text" value="<? echo $_POST['submit'] == 'Ping' ? htmlentities($ping_ip_addr, ENT_QUOTES) : $_SERVER['REMOTE_ADDR'];; ?>" size="40" maxlength="15" /></p>
<p><label for="ping_count">Ping Sayısı:</label><br />
<select name="ping_count" id="ping_count">
<?
foreach ($ping_count_array as $ping_count_item)
{
echo '<option' . ($ping_count == $ping_count_item ? ' selected="selected"' : '') . '>' . $ping_count_item . '</option>' . "
";
}
?>
</select></p>
<p><input type="submit" name="submit" value="Ping At" /></p>
</>
<p>Ping atma işlemi zaman alabilir, lütfen bekleyiniz.</p>
<?

if ($_POST['submit'] == 'Ping At')
{
echo '<div class="output">' . "
";

$illegal = FALSE;

if (strlen($ping_ip_addr) > 15)
{
$illegal = TRUE;
}

if (!in_array($ping_count, $ping_count_array))
{
$illegal = TRUE;
}

if (!$illegal) // submission was not spoofed.
{
if (ereg('^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$', $ping_ip_addr)) // Acquired data contains no problems.
{
// Display result.

echo '<pre>' . "
" .
'ping -c ' . $ping_count . ' ' . $ping_ip_addr . "

";

system('ping -c ' . $ping_count . ' ' . $ping_ip_addr);

echo '</pre>' . "
" .
'<p>Ping tamamlandı.</p>' . "
";
}
else
{
echo '<p>Lütfen geçerli bir IP giriniz.</p>' . "
";
}
}
else
{
echo '<p>Bir oluştu.</p>' . "
";
}

echo '</div>' . "
";
}
?>
</body>
</>

kaynak: ordan burdan

ana klasörün altına (root yani index. nin olduğu yer)
.htaccess isminde bir dosya oluşturun, aşağıdaki satırları bu dosyaya kayıtedin.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?adresiniz.com.*$ [NC]
RewriteRule ^.+.(jpg|jpeg|png|gif||)$ - [NC,F,L]

kaynak: ordan burdan

<?
$file = "otelreferans.txt";

$lines = count(file($file));

echo $lines." satır var";
?>

kaynak: ordan burdan

<?

$URL="http://www.codekodu.com/.";

header ("Location: $URL");

?>

kaynak: ordan burdan

<?

echo "<p>IP Addresi: " . $_SERVER['REMOTE_ADDR'] . "</p>";

echo "<p>Nereden geldiği (Referans): " . $_SERVER['HTTP_REFERER'] . "</p>";

echo "<p>Browser: " . $_SERVER['HTTP_USER_AGENT'] . "</p>";

?>

kaynak: ordan burdan

<?

//sayfadaki kod bloğunun en üstüne koyun
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$start = $time;

//sayfadaki kod bloğunun en altına koyun
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$finish = $time;
$totaltime = ($finish - $start);
printf ("bu sayfanın %f yüklenme süresi.", $totaltime);

?

kaynak: ordan burdan

<?

$string = "This is some text and numbers 12345 and symbols !£$%^&";

$yeni_string = ereg_replace("[^A-Za-z0-9]", "", $string);

echo $yeni_string

?>

kaynak: ordan burdan

$text = "mixedcharacters012345&../@";

if (ereg('[^A-Za-z0-9]', $text)) {
echo "geçersiz karakter var";
}
else {
echo "geçersiz karakter yok";
}

kaynak: ordan burdan

<?

$sql = "SELECT name FROM ogrenci";

$result = mysql_query($sql);

$thenumber = 1;

while ($row = mysql_fetch_array ($result)) {

echo $thenumber . ' - ' . $row['adi'];

$thenumber++;
}

?>

kaynak: ordan burdan

<?

dbConnect()

$alltables = mysql_query("SHOW TABLES");

while ($table = mysql_fetch_assoc($alltables))
{

foreach ($table as $db => $tablename)
{
mysql_query("OPTIMIZE TABLE '".$tablename."'")
or die(mysql_error());
}

}

?>

kaynak: ordan burdan

<?

$path = "/home/user/public/foldername/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle)) {

if($file == "." || $file == ".." || $file == "index." )

continue;
echo "<a href="$file">$file</a><br />";

}

// Close
closedir($dir_handle);

?>

kaynak: ordan burdan

<?

$toplam = "11";
$resim_uzantisi = ".jpg";
$resim_klasoru = "resimlerim/buyuk_resimler";

$ilk = "1";

$rastgele = mt_rand($ilk, $toplam);

$resim_adi = $rastgele . $resim_uzantisi;

echo "<img src="$resim_klasoru/$resim_adi" alt="$resim_adi" />";

?>

kaynak: ordan burdan