الفرق بين المراجعتين ل"PHP/count chars"

من موسوعة حسوب
< PHP
اذهب إلى التنقل اذهب إلى البحث
 
(مراجعة متوسطة واحدة بواسطة نفس المستخدم غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE:الدالة count_chars()‎ في PHP}}</noinclude>
+
<noinclude>{{DISPLAYTITLE:الدالة <code>count_chars()‎</code> في PHP}}</noinclude>
 
(PHP 4, PHP 5, PHP 7)
 
(PHP 4, PHP 5, PHP 7)
  
تعيد الدالة ‎count_chars()‎ معلومات عن الأحرف الموجودة بالسلسلة النصية.
+
تعيد الدالة ‎<code>count_chars()</code>‎ معلومات عن الأحرف الموجودة بالسلسلة النصية.
  
=== الوصف ===
+
== الوصف ==
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
 
mixed count_chars ( string $string [, int $mode = 0 ] )
 
mixed count_chars ( string $string [, int $mode = 0 ] )
 
</syntaxhighlight>تعيد الدالة عدد التكرارات لكل قيمة بايت (byte-value) من القيمة 0 إلى 255 في سلسلة نصية بطرائق مختلفة.
 
</syntaxhighlight>تعيد الدالة عدد التكرارات لكل قيمة بايت (byte-value) من القيمة 0 إلى 255 في سلسلة نصية بطرائق مختلفة.
  
=== المعاملات ===
+
== المعاملات ==
  
==== string ====
+
=== <code>string</code> ===
 
السلسلة النصية التي نريد فحصها.
 
السلسلة النصية التي نريد فحصها.
  
==== mode ====
+
=== <code>mode</code> ===
يحدد طريقة عمل الدالة count_chars()‎.
+
يحدد طريقة عمل الدالة <code>count_chars()‎</code>.
  
=== القيم المعادة ===
+
== القيم المعادة ==
تختلف القيم المعادة للدالة count_chars()‎ على حسب قيمة المعامل mode كما يلي:
+
تختلف القيم المعادة للدالة <code>count_chars()‎</code> على حسب قيمة المعامل <code>mode</code> كما يلي:
* 0: تعيد الدالةُ مصفوفةَ بياناتٍ. إذ يكون مفتاح الجدول هو قيمة البايت وقيم المصفوفة هي عدد التكرارات لكل مفتاح.
+
* <code>0</code>: تعيد الدالةُ مصفوفةَ بياناتٍ. إذ يكون مفتاح الجدول هو قيمة البايت وقيم المصفوفة هي عدد التكرارات لكل مفتاح.
* 1: نفس مبدأ عمل الدالة count_chars()‎ عندما يكون المعامل mode يساوي 0 لكن تعيد عدد التكرارات غير المعدومة فقط.
+
* <code>1</code>: نفس مبدأ عمل الدالة <code>count_chars()‎</code> عندما يكون المعامل <code>mode</code> يساوي <code>0</code> لكن تعيد عدد التكرارات غير المعدومة فقط.
* 2: نفس مبدأ عمل الدالة count_chars()‎ عندما يكون المعامل mode يساوي 0 لكن تعيد عدد التكرارات المعدومة فقط أي تعيد كل الحروف غير الموجودة بالمعامل string.
+
* <code>2</code>: نفس مبدأ عمل الدالة <code>count_chars()‎</code> عندما يكون المعامل <code>mode</code> يساوي <code>0</code> لكن تعيد عدد التكرارات المعدومة فقط أي تعيد كل الحروف غير الموجودة بالمعامل <code>string</code>.
* 3: تعيد الدالة count_chars()‎ سلسلة نصية تحتوي على كل الأحرف غير المكررة.
+
* <code>3</code>: تعيد الدالة <code>count_chars()‎</code> سلسلة نصية تحتوي على كل الأحرف غير المكررة.
* 4: تعيد الدالة count_chars()‎ سلسلة نصية تحتوي على جميع الأحرف غير المستخدمة.
+
* <code>4</code>: تعيد الدالة <code>count_chars()‎</code> سلسلة نصية تحتوي على جميع الأحرف غير المستخدمة.
  
=== أمثلة ===
+
== أمثلة ==
 
+
المثال 1: مثال بسيط عن الدالة <code>count_chars()‎</code><syntaxhighlight lang="php">
==== المثال 1: مثال بسيط عن الدالة count_chars()‎ ====
 
<syntaxhighlight lang="php">
 
 
<?php
 
<?php
 
 
$data = "Two Ts and one F.";
 
$data = "Two Ts and one F.";
  
 
foreach (count_chars($data, 1) as $i => $val) {
 
foreach (count_chars($data, 1) as $i => $val) {
 
 
  echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
 
  echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
 
 
}
 
}
 
 
?>
 
?>
  
 
+
</syntaxhighlight>سيُخرِج المثال السابق الناتج الآتي:<syntaxhighlight lang="text">
</syntaxhighlight>سيُخرِج المثال السابق الناتج الآتي:<syntaxhighlight lang="php">
 
 
There were 4 instance(s) of " " in the string.
 
There were 4 instance(s) of " " in the string.
 
 
There were 1 instance(s) of "." in the string.
 
There were 1 instance(s) of "." in the string.
 
 
There were 1 instance(s) of "F" in the string.
 
There were 1 instance(s) of "F" in the string.
 
 
There were 2 instance(s) of "T" in the string.
 
There were 2 instance(s) of "T" in the string.
 
 
There were 1 instance(s) of "a" in the string.
 
There were 1 instance(s) of "a" in the string.
 
 
There were 1 instance(s) of "d" in the string.
 
There were 1 instance(s) of "d" in the string.
 
 
There were 1 instance(s) of "e" in the string.
 
There were 1 instance(s) of "e" in the string.
 
 
There were 2 instance(s) of "n" in the string.
 
There were 2 instance(s) of "n" in the string.
 
 
There were 2 instance(s) of "o" in the string.
 
There were 2 instance(s) of "o" in the string.
 
 
There were 1 instance(s) of "s" in the string.
 
There were 1 instance(s) of "s" in the string.
 
 
There were 1 instance(s) of "w" in the string.
 
There were 1 instance(s) of "w" in the string.
 
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== انظر أيضًا ===
+
== انظر أيضًا ==
* strpos()‎: إيجاد موقع أول ظهور لسلسة نصية فرعية داخل سلسلة نصية.
+
* <code>[[PHP/strpos|strpos()‎]]</code>: إيجاد موقع أول ظهور لسلسة نصية فرعية داخل سلسلة نصية.
* substr_count()‎: حساب عدد تكرارات السلسلة الفرعية.
+
* <code>[[PHP/substr count|substr_count()‎]]</code>: حساب عدد تكرارات السلسلة الفرعية.
  
=== مصادر ===
+
== مصادر ==
* صفحة الدالة count_chars‎ في توثيق PHP الرسمي.
+
* [http://php.net/manual/en/function.count-chars.php صفحة الدالة count_chars‎ في توثيق PHP الرسمي].
 +
[[تصنيف:PHP]]
 +
[[تصنيف:PHP Function]]
 +
[[تصنيف:PHP String]]

المراجعة الحالية بتاريخ 15:36، 5 أبريل 2018

(PHP 4, PHP 5, PHP 7)

تعيد الدالة ‎count_chars()‎ معلومات عن الأحرف الموجودة بالسلسلة النصية.

الوصف

mixed count_chars ( string $string [, int $mode = 0 ] )

تعيد الدالة عدد التكرارات لكل قيمة بايت (byte-value) من القيمة 0 إلى 255 في سلسلة نصية بطرائق مختلفة.

المعاملات

string

السلسلة النصية التي نريد فحصها.

mode

يحدد طريقة عمل الدالة count_chars()‎.

القيم المعادة

تختلف القيم المعادة للدالة count_chars()‎ على حسب قيمة المعامل mode كما يلي:

  • 0: تعيد الدالةُ مصفوفةَ بياناتٍ. إذ يكون مفتاح الجدول هو قيمة البايت وقيم المصفوفة هي عدد التكرارات لكل مفتاح.
  • 1: نفس مبدأ عمل الدالة count_chars()‎ عندما يكون المعامل mode يساوي 0 لكن تعيد عدد التكرارات غير المعدومة فقط.
  • 2: نفس مبدأ عمل الدالة count_chars()‎ عندما يكون المعامل mode يساوي 0 لكن تعيد عدد التكرارات المعدومة فقط أي تعيد كل الحروف غير الموجودة بالمعامل string.
  • 3: تعيد الدالة count_chars()‎ سلسلة نصية تحتوي على كل الأحرف غير المكررة.
  • 4: تعيد الدالة count_chars()‎ سلسلة نصية تحتوي على جميع الأحرف غير المستخدمة.

أمثلة

المثال 1: مثال بسيط عن الدالة count_chars()‎

<?php
$data = "Two Ts and one F.";

foreach (count_chars($data, 1) as $i => $val) {
  echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
}
?>

سيُخرِج المثال السابق الناتج الآتي:

There were 4 instance(s) of " " in the string.
There were 1 instance(s) of "." in the string.
There were 1 instance(s) of "F" in the string.
There were 2 instance(s) of "T" in the string.
There were 1 instance(s) of "a" in the string.
There were 1 instance(s) of "d" in the string.
There were 1 instance(s) of "e" in the string.
There were 2 instance(s) of "n" in the string.
There were 2 instance(s) of "o" in the string.
There were 1 instance(s) of "s" in the string.
There were 1 instance(s) of "w" in the string.

انظر أيضًا

  • strpos()‎: إيجاد موقع أول ظهور لسلسة نصية فرعية داخل سلسلة نصية.
  • substr_count()‎: حساب عدد تكرارات السلسلة الفرعية.

مصادر