Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Count the number of substring occurrences
<?php substr_count( string $haystack, string $needle, int $offset = 0, ?int $length = null): int
<?php public static function substrCount($haystack, $needle, $offset = 0, $length = null)
{
if (! is_null($length)) {
return substr_count($haystack, $needle, $offset, $length);
}
return substr_count($haystack, $needle, $offset);
<?php return substr_count($haystack, $needle, $offset, $length);
}
return substr_count($haystack, $needle, $offset);
}
<?php $query = EloquentTestUser::has('postWithPhotos');
$bindingsCount = count($query->getBindings());
$questionMarksCount = substr_count($query->toSql(), '?');
$this->assertEquals($questionMarksCount, $bindingsCount);
}
<?php while ($matchesCount > 0) {
$orderByPos = $matches[0][--$matchesCount][1];
$openBracketsCount = substr_count($query, '(', $orderByPos);
$closedBracketsCount = substr_count($query, ')', $orderByPos);
if ($openBracketsCount === $closedBracketsCount) {
return false;
<?php while ($matchesCount > 0) {
$orderByPos = $matches[0][--$matchesCount][1];
$openBracketsCount = substr_count($query, '(', $orderByPos);
$closedBracketsCount = substr_count($query, ')', $orderByPos);
if ($openBracketsCount === $closedBracketsCount) {
return false;
}
<?php $repo = null;
$id = $reference;
if (substr_count($id, '::')) {
[$repo, $id] = explode('::', $id, 2);
}
<?php public function process($data)
{
if (substr_count($data, "\n") > 0 || substr_count($data, ': ') > 0) {
$data = \Statamic\Facades\Yaml::parse($data);
}
<?php $folders->sort(function ($a, $b) {
return (substr_count($a, '/') >= substr_count($b, '/')) ? -1 : 1;
});
<?php $dir = str_finish($this->directory, '/');
$relative = str_after(Path::tidy($file->getPathname()), $dir);
return $file->getExtension() === 'yaml' && substr_count($relative, '/') === 0;
}
public function makeItemFromFile($path, $contents)
<?php $filename = str_after(Path::tidy($file->getPathName()), $this->directory);
return substr_count($filename, '/') === 0 && $file->getExtension() === 'yaml';
}
public function makeItemFromFile($path, $contents)
<?php $filename = str_after(Path::tidy($file->getPathName()), $this->directory);
return substr_count($filename, '/') === 0 && $file->getExtension() === 'yaml';
}
public function makeItemFromFile($path, $contents)
<?php $path = Str::after($path, $this->directory);
$path = Str::before($path, '.yaml');
if (substr_count($path, '/') === 0) {
return [Site::default()->handle(), $path];
}
<?php {
$filename = str_after(Path::tidy($file->getPathName()), $this->directory);
return $file->getExtension() === 'yaml' && substr_count($filename, '/') === 0;
}
public function makeItemFromFile($path, $contents)
<?php foreach (Folder::getFilesRecursively($folder) as $path) {
$slashes = substr_count($path, '/') - substr_count($folder, '/');
if ($slashes <= $depth) {
$folder_files[] = $path;
<?php if ($minWords = $input->getOption('min-words')) {
$rows = $rows->filter(function ($item) use ($minWords) {
return substr_count($item['string'], ' ') >= ($minWords - 1);
});
}