PHP Kod Kütüphanesi

peep

0
İyinet Üyesi
Onaylı Üye
Katılım
20 Mayıs 2007
Mesajlar
6,382
Reaction score
86
Php konusunda aranan kodlara yardımcı olmak amacıyla bu konuyu açmak istedim. Bu konuda altında paylaşabileceğimiz php kodları paylaşalım.

Eminimki bu konu php öğrenmek isteyenlere ve yeni yeni öğrenenlere yardımcı olacaktır.

Konuya ilgi gösteren bütün arkadaşlara teşekkür ederim.
 

peep

0
İyinet Üyesi
Onaylı Üye
Katılım
20 Mayıs 2007
Mesajlar
6,382
Reaction score
86
Negatif Sayıları Pozitife çevirme

abs fonksiyonu ile netagif olan değişkeni pozitife çevirebiliyoruz.

PHP:
<?php

$abs = abs(-4.2); // $abs = 4.2; (double/float)
$abs2 = abs(5);   // $abs2 = 5; (integer)
$abs3 = abs(-5);  // $abs3 = 5; (integer)

echo $abs;
echo $abs2;
echo $abs3;

?>
 

peep

0
İyinet Üyesi
Onaylı Üye
Katılım
20 Mayıs 2007
Mesajlar
6,382
Reaction score
86
Türkçe karakter replace

Hepimizin urlleri sef yaparken işimize yarayan bir fonksiyon bu fonksiyon ile urldeki türkçe karakterlere çözüm bulabiliyoruz.
PHP:
<?php
function replace_tr($text) {
$text = trim($text);
$search = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü',' ');
$replace = array('C','c','G','g','i','i','O','o','S','s','U','u','-');
$new_text = str_replace($search,$replace,$text);
return $new_text;
} 

# Kullanımı
$yazi="Sensiz geçenmez her günüm";
echo replace_tr($yazi);
?>
 

GNeRaL

0
İyinet Üyesi
Katılım
24 Şubat 2005
Mesajlar
2,869
Reaction score
16
Konum
Samsun
PHP:
foreach ($_POST as $key => $value) { 
$$key = addslashes(htmlspecialchars($value)); 
}

Tüm _POST verilerini herhangi bir uzatma şekli kullanmadan direkt değer olarak kullanmanızı sağlar.
 

peep

0
İyinet Üyesi
Onaylı Üye
Katılım
20 Mayıs 2007
Mesajlar
6,382
Reaction score
86
Mysql bağlantısı

Mysql bağlantısı konusunda bilginiz yok ise...

PHP:
<?php
mysql_connect("localhost", "bingom_mp3", "123456") or die ("Veritabanı Kullanıcısı Hatası NO: 1 ");
mysql_select_db("bingom_mp3") or die ("Database Hatası NO: 2");
?>
 

peep

0
İyinet Üyesi
Onaylı Üye
Katılım
20 Mayıs 2007
Mesajlar
6,382
Reaction score
86
Değişkenimizi html kodlardan arındırmak istiyorsak
PHP:
<?php

$veri=("<b>Bugun</b>: Yarına <font size='12px;'>bir habercidir</font><br /> <h1>H1 Tag</h1>");

echo strip_tags($veri);

# çıktısı: Bugun: yarına bir habercidir H1 Tag

?>
 

yagmayok

1
İyinet Üyesi
Katılım
25 Ocak 2005
Mesajlar
7,131
Reaction score
89
PHP:
function seo($url)
{
    $url = trim($url);
    $url = strtolower($url);

    $find = array('<b>', '</b>');
    $url = str_replace ($find, '', $url);

    $url = preg_replace('/<(\/{0,1})img(.*?)(\/{0,1})\>/', 'image', $url);

    $find = array(' ', '"', '&', '&', '\r\n', '\n', '/', '\\', '+', '<', '>');
    $url = str_replace ($find, '-', $url);

    $find = array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ë', 'Ê');
    $url = str_replace ($find, 'e', $url);

    $find = array('í', 'ı', 'ì', 'î', 'ï', 'I', 'İ', 'Í', 'Ì', 'Î', 'Ï');
    $url = str_replace ($find, 'i', $url);

    $find = array('ó', 'ö', 'Ö', 'ò', 'ô', 'Ó', 'Ò', 'Ô');
    $url = str_replace ($find, 'o', $url);

    $find = array('á', 'ä', 'â', 'à', 'â', 'Ä', 'Â', 'Á', 'À', 'Â');
    $url = str_replace ($find, 'a', $url);

    $find = array('ú', 'ü', 'Ü', 'ù', 'û', 'Ú', 'Ù', 'Û');
    $url = str_replace ($find, 'u', $url);

    $find = array('ç', 'Ç');
    $url = str_replace ($find, 'c', $url);

    $find = array('ş', 'Ş');
    $url = str_replace ($find, 's', $url);

    $find = array('ğ', 'Ğ');
    $url = str_replace ($find, 'g', $url);

    $find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');

    $repl = array('', '-', '');

    $url = preg_replace ($find, $repl, $url);
    $url = str_replace ('--', '-', $url);

    return $url;
}

$yazi = "Şebnem Ferah / Babam Oğlum ( dinle )";
$echo seo($yazi);

Linkleri sef yapmak için benim kullandığım php fonksiyonu yukardaki gibidir. Sorunsuz olarak çalışmaktadır.
 

NeFuSa

0
İyinet Üyesi
Katılım
27 Aralık 2006
Mesajlar
1,414
Reaction score
15
Konum
İstanbul
Sef Fonksiyonu

Fonksiyon Kodları :

PHP:
<?php
function kisalt($deger) {
if (strlen($deger) >'250') {
$deger = substr("$deger",0,245)."...";
}
return $deger;
}

function turkce_yap($deger) {
 $bozuk=array(" ","i","I","s","S","ö","Ö","ü","Ü","ç","İ","Ç","&","_#350;","_#305;","'","\"","_#287;","?","%","#8217;","A","B","C","D","E","F","G","H","I","J","K","L","M","N","P","R","S","Ş","T","U","V","W","X","Y","Z","ğ","ı","ş","Ş","O","--","WWW","www"," - ","(",")",",");
 $duzgun=array("-","i","i","s","s","o","o","u","u","c","i","c","","","","","","","","","","a","b","c","d","e","f","g","h","i","j","k","l","m","n","p","r","s","ş","t","u","v","w","x","y","z","g","i","s","s","o","-","","","","","");
 $metin=urldecode($deger);
 $metin=str_replace($bozuk,$duzgun,$metin);
 return $metin;
}

function iyice_duzelt($deger) {
$bul=array('ı','ü','Å?','ç','ö','Ä?','Å?ov','ÄŸ','ÅŸ','Ä°','Ä°','Å ','ä','"','.','é','é','ú','º','ã','ê','É',':','%','½','Ä ','(',')','[',']','/','ş','ı','ğ');
$degis=array('i','u','s','c','o','g','Sov','g','s','I','I','S','a','','','e','e','u','','a','e','E','','','','G','-','-','-','-','-','s','i','g');
$deger = str_replace($bul,$degis,$deger);
return $deger;
}
?>

Fonksiyon Kullanımı :

PHP:
$duzenlenmisdegisken = turkce_yap($duzenlenecekdegisken);
$duzenlenmisdegisken = iyice_duzelt($duzenlenmisdegisken);
$duzenlenmisdegisken = kisalt($duzenlenmisdegisken);
 

NeFuSa

0
İyinet Üyesi
Katılım
27 Aralık 2006
Mesajlar
1,414
Reaction score
15
Konum
İstanbul
Youtube videolarını istediğiniz formatta indirtin/oynatin/dinletin

Youtube'daki videoları istediğiniz formatta yükletebilir, oynatabilir ve dinletebilirsiniz. Bu kodlar ile Youtube logosu olmadan kendi playerınızda video oynatabilirsiniz. Videoların sadece müziklerini yine kendi playerınızda dinletebilirsiniz. Ayrıca bu videoları istediğiniz formatta indirtebilirsiniz. php dosyasının bulunduğu dizine boş bir cache.xml dosyası yaratın.

download.php olduğunu varsayalım;
PHP:
<?php

	/** Ayarlar
	*/
	$cache_url = 'cache.xml'; //Cache Adresi
	$cache_time = 30;
	
	$video_id = $_GET['v'];
	
	/**
	*/
	parse_str(file_get_contents("http://youtube.com/get_video_info?video_id={$video_id}"),$i);
	if($i['status'] == 'fail' && $i['errorcode'] != '150') die(header("Location: errors/error01.mp4")); //Hata
	
	if($i['status'] == 'fail') { //150 HATA KODU 
		//Cache Dosyası
		if(!isset($cache_url)) $cache_url = "cache.xml";
		$cache = file_get_contents($cache_url);
		if( time() - $cache  < $cache_time && isset($cache_time)) die(header("Location: errors/error02.mp4"));
			$cache = fopen($cache_url, "w");
			fwrite($cache, time());
			fclose($cache);
		//
		$content = file_get_contents("http://www.youtube.com/watch?v={$video_id}");
		preg_match_all ("/(\\{.*?\\})/is", $content, $matches); 
		$obj = json_decode($matches[0][1]);
		
		$token = $obj->{'t'}; $fmt_map = $obj->{'fmt_map'}; $fmt_url_map = $obj->{'fmt_url_map'};
	}
	else { //Hata yok
		$token = $i['token']; $fmt_map = $i['fmt_map']; $fmt_url_map = $i['fmt_url_map'];
	}
	
	//Video Formatı (fmt ile belirliyoruz)
	if(!isset($fmt_map)) die(header("Location: errors/error03.mp4"));
	preg_match_all ("/(.*?),/is", $fmt_map, $fmt_map);
	foreach( $fmt_map[1] as $fmt_i => $fmt_value){
		$fmt_value = explode('/',$fmt_value);
		if ($fmt_value[0] == 22) {$fmt = 22;} else{$fmt = 18;}
	}
	$url = "http://www.youtube.com/get_video.php?video_id={$video_id}&vq=2&fmt={$fmt}&t={$token}";
	$headers = get_headers($url,1);
	
	$video = $headers['Location'];
	if(!isset($video)) {
		$fmt_url_map = explode(',',$fmt_url_map);
		foreach( $fmt_url_map as $fmt_i => $fmt_url){
			$fmt_url = explode('|',$fmt_url);
			if($fmt_url[0] == 22 || $fmt_url[0] == 18) $video = $fmt_url[1]; break;
		}
	}
	if(!isset($video)) die(header("Location: errors/error01.mp4"));

	is_array($video) ? $video = $video[0] : $video = $video;
	header("Location: $video"); //Düzenlenmiş video linki
		echo "$url";
?>

Kullanımı;

download.php?v=youtube_id(ABcdEfgHjkL)
 

Ozcan

0
İyinet Üyesi
Katılım
12 Mayıs 2007
Mesajlar
3,749
Reaction score
59
Konum
Antalya
PHP:
<?php 
// Sayfa include etme sayfa ekleme
include "ayar.php";

// veri tabani baglantisi
mysql_connect(host_adi,kullanici_adi,sifre);
@mysql_select_db(veritabani_adi);


// veri sorgulama
$uyeler=mysql_query("select * from uye");
while($uye=mysql_fetch_array($uyeler)) {



// Degisken yazdirma iki ayri sekilde
echo '<a href="sil.php?id='.$uye[id].'">'.$uye[kullanici].'</a>';
echo "<br />";
echo "<a href=\"sil.php?id=$uye[id]\">$uye[kullanici]</a>";
echo "<br />";

//Uyenin son ekledigi mesaj
$mesajlar=mysql_query("select * from konu where uyeid=$uye[id] order by id desc");
$mesaj=mysql_fetch_array($mesajlar);
echo "$mesaj[6]<br />";
} 
?>
<--! HTML FORMU -->
<form action="test.php" method="get">
<input name="uye" type="text" />
</form>

<?php

// Get ve Post Metodu ile veri alma

$uye1=$_POST[uye];
$uye2=$_GET[uye];

// if fonksiyonu
if ($uye1!=''){$uye=$uye1;}

if ($uye2==''){ $uye='Bos'; } else { $uye='Bos degil'; }

if ($uye3=='' and $uye2!='' or $uye1==8) { echo "Sonuç";}


// Veri güncelleme
mysql_query("UPDATE  `uye` SET  `sifre` =  'sifre' WHERE  `uye`.`sifre` =12345");

// Veri Ekleme
mysql_query("INSERT INTO  `uye` (
`id` ,`isim` ,`kullanici` ,`sifre` ,`mail` ,`onay` ,`seviye`)VALUES (
lisanssız ,'$uye','$uye',  '12345',  '[email protected]',  'e',  '1'
)"); 


// Metematik islemleri
echo 14+5;
echo "<br />";
echo 14-5;
echo "<br />";
echo 14*5;

?>
 

atay

0
İyinet Üyesi
Katılım
29 Ekim 2005
Mesajlar
3,592
Reaction score
37
Değişken ile Değişken Almak

PHP:
<?
$org='www';
$sardunya='org';
echo $$sardunya;
// Sonuç: www
?>

Kısa If İşlemi

PHP:
<?
$deger=1;
$yazdir=(($deger == 1)? 'bir' : 'degil');
echo $yazdir;
?>

Break ve Continue - Örnek

PHP:
<?
$say=0;
while ($say <10) {
if ($say == 5) {
$say++;
continue;
}
if ($say == 8) {
break;
}
echo $say.'<br>';
$say++;
}
?>
 

Taylan

0
Yasakli Uye
Katılım
8 Ağustos 2009
Mesajlar
771
Reaction score
10
Konum
Ankara
Siteye gelen ziyaretçilerin ip(internet protocol)adreslerini gösterme

PHP:
Kod:
<?phpecho $_SERVER['REMOTE_ADDR'];?>

PHP:
Kod:<?php
// Dosya Türü
header("Content-type: image/png");

// Resim oluşturuluyor
$im = imagecreatetruecolor(400, 30);

// Renkler oluşturuluyor
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// Yazı yazılıyor
$text = 'webster...';

// Font seçiliyor
$font = 'arial.ttf';

// Yazıya gölge ekleneiyor
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Resim üzerine yazı ekleniyor
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

.htaccess ile sayfaları klasör olarak gösterme

PHP:
Kod:RewriteEngine on

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

*********

gelen linkimiz
http://www.siteismi.com/linkler/iyinet

***********************************************

php dosyası

**********************

<?php

$url = explode("/",$_GET['q']);

if (isset($url[0]) && $url[0] == 'linkler' && isset($url[1]) && isnumeric($url[1])) {
include('linkler.php');
exit();
}

//yukarıdaki if bloğunuzu oluşturacağınız klasör sayısı kadar yazmalısınız. Bu blokların hepsinden geçeni ise ana sayfaya yönlendirebilirsiniz.

?>

dipnot: .htaccess dosyasına yazılıp anadizine atılacaktır.
 

berxocan

0
İyinet Üyesi
Katılım
15 Nisan 2012
Mesajlar
4
Reaction score
0
Selam ben Sesli Site acmasını orenmek ıstıyorum bu konuda yardımcı OLursanız Cok Sevınırım pek fazla bılgım yok nerden baslamam gerekıor lutfen yardımcı OLun tşk
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Backlink ve Tanıtım Yazısı için iletişime geçmek için Skype Adresimiz: .cid.1580508955483fe5

Elektronik Sigara Cicisex Porno
Üst