PHP handleiding

PHP TUIS PHP Inleiding PHP installeer PHP sintaksis PHP opmerkings PHP veranderlikes PHP Echo / Druk PHP datatipes PHP Strings PHP-nommers PHP Wiskunde PHP konstante PHP-operateurs PHP As...Anders...Elseif PHP skakelaar PHP-lusse PHP funksies PHP-skikkings PHP Superglobals PHP RegEx

PHP- vorms

PHP-vormhantering PHP-vorm validering PHP-vorm word vereis PHP-vorm URL/e-pos PHP-vorm voltooi

PHP Gevorderd

PHP datum en tyd PHP sluit in PHP-lêerhantering PHP-lêer oop/lees PHP-lêer skep/skryf PHP-lêer oplaai PHP-koekies PHP-sessies PHP filters PHP-filters Gevorderd PHP-terugbelfunksies PHP JSON PHP-uitsonderings

PHP OOP

PHP Wat is OOP PHP Klasse/Objekte PHP Konstrukteur PHP vernietiger PHP Toegangswysigers PHP erfenis PHP konstante PHP Abstrakte Klasse PHP-koppelvlakke PHP eienskappe PHP statiese metodes PHP Statiese Eienskappe PHP naamruimtes PHP Iterables

MySQL- databasis

MySQL-databasis MySQL Connect MySQL Skep DB MySQL Skep tabel MySQL Voeg data in MySQL Kry Laaste ID MySQL Voeg veelvuldige in MySQL voorberei MySQL Kies Data MySQL Waar MySQL Bestel deur MySQL verwyder data MySQL-opdateringsdata MySQL-limietdata

PHP XML

PHP XML-ontleders PHP SimpleXML-ontleder PHP SimpleXML - Kry PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX Intro AJAX PHP AJAX-databasis AJAX XML AJAX Live Search AJAX-peiling

PHP voorbeelde

PHP voorbeelde PHP samesteller PHP vasvra PHP Oefeninge PHP-sertifikaat

PHP- verwysing

PHP Oorsig PHP Skikking PHP-kalender PHP datum PHP gids PHP fout PHP-uitsondering PHP lêerstelsel PHP filter PHP FTP PHP JSON PHP sleutelwoorde PHP Libxml PHP-pos PHP Wiskunde PHP Diverse PHP MySQLi PHP-netwerk PHP-uitsetbeheer PHP RegEx PHP SimpleXML PHP-stroom PHP-string PHP veranderlike hantering PHP XML-ontleder PHP zip PHP Tydsones

PHP substr_count() Funksie

❮ PHP-stringverwysing

Voorbeeld

Tel die aantal kere wat "wêreld" in die string voorkom:

<?php
echo substr_count("Hello world. The world is nice","world");
?>

Die substr_count() funksie tel die aantal kere wat 'n substring in 'n string voorkom.

Let wel: Die substring is hooflettersensitief.

Let wel: Hierdie funksie tel nie oorvleuelde substringe nie (sien voorbeeld 2).

Let wel: Hierdie funksie genereer 'n waarskuwing as die begin parameter plus die lengte parameter groter is as die string lengte (sien voorbeeld 3).


Sintaksis

substr_count(string,substring,start,length)

Parameterwaardes

Parameter Description
string Required. Specifies the string to check
substring Required. Specifies the string to search for
start Optional. Specifies where in string to start searching. If negative, it starts counting from the end of the string
length Optional. Specifies the length of the search


Tegniese besonderhede

Terugkeerwaarde: Wys die aantal kere wat die substring in die string voorkom
PHP weergawe: 4+
Veranderinglog: PHP 7.1 - Die lengte parameters kan 0 of 'n negatiewe getal wees.
PHP 7.1 - Die beginparameters kan 'n negatiewe getal wees.
PHP 5.1 - Die begin- en lengteparameters is bygevoeg.

Meer voorbeelde

Voorbeeld

Gebruik alle parameters:

<?php
$str = "This is nice";
echo strlen($str)."<br>"; // Using strlen() to return the string length
echo substr_count($str,"is")."<br>"; // The number of times "is" occurs in the string
echo substr_count($str,"is",2)."<br>"; // The string is now reduced to "is is nice"
echo substr_count($str,"is",3)."<br>"; // The string is now reduced to "s is nice"
echo substr_count($str,"is",3,3)."<br>"; // The string is now reduced to "s i"
?>

Voorbeeld

Oorvleuelde substringe:

<?php
$str = "abcabcab";
echo substr_count($str,"abcab"); // This function does not count overlapped substrings
?>

Voorbeeld

As die begin- en lengteparameters die stringlengte oorskry, sal hierdie funksie 'n waarskuwing uitstuur:

<?php
echo $str = "This is nice";
substr_count($str,"is",3,9);
?>

Dit sal 'n waarskuwing gee omdat die lengtewaarde die stringlengte oorskry (3+9 is groter as 12)


❮ PHP-stringverwysing