PHP substr() İşlev
Örnek
Dizeden "dünya" döndür:
<?php
echo substr("Hello world",6);
?>
Tanım ve Kullanım
substr() işlevi, bir dizenin bir bölümünü döndürür.
Sözdizimi
substr(string,start,length)
Parametre Değerleri
Parameter | Description |
---|---|
string | Required. Specifies the string to return a part of |
start | Required. Specifies where to start in the string
|
length | Optional. Specifies the length of the returned string. Default is to the end of the string.
|
Teknik detaylar
Geri dönüş değeri: | Bir dizenin ayıklanan kısmını veya hata durumunda FALSE veya boş bir dize döndürür |
---|---|
PHP Sürümü: | 4+ |
Değişiklik günlüğü: | PHP 7.0 - Eğer string = start (karakter uzunluğunda) ise, boş bir string döndürür. Önceki sürümler YANLIŞ döndürür. PHP 5.2.2 - 5.2.6 - start negatif bir kesme konumuna sahipse, FALSE döndürülür. Diğer sürümler dizeyi baştan alır. |
Daha fazla örnek
Örnek
Başlangıç parametresini farklı pozitif ve negatif sayılarla kullanma:
<?php
echo substr("Hello world",10)."<br>";
echo substr("Hello world",1)."<br>";
echo substr("Hello world",3)."<br>";
echo substr("Hello world",7)."<br>";
echo substr("Hello world",-1)."<br>";
echo substr("Hello world",-10)."<br>";
echo substr("Hello world",-8)."<br>";
echo substr("Hello world",-4)."<br>";
?>
Örnek
Başlangıç ve uzunluk parametrelerini farklı pozitif ve negatif sayılarla kullanma:
<?php
echo substr("Hello world",0,10)."<br>";
echo substr("Hello world",1,8)."<br>";
echo substr("Hello world",0,5)."<br>";
echo substr("Hello world",6,6)."<br>";
echo substr("Hello world",0,-1)."<br>";
echo substr("Hello world",-10,-2)."<br>";
echo substr("Hello world",0,-6)."<br>";
?>
❮ PHP Dize Referansı