دالة PHP strtr ()
مثال
استبدل الأحرف "ia" في السلسلة بـ "eo":
<?php
echo strtr("Hilla Warld","ia","eo");
?>
التعريف والاستخدام
تترجم الدالة strtr () أحرفًا معينة في سلسلة نصية.
ملاحظة: إذا كانت المعلمات من وإلى مختلفة في الطول ، فسيتم تنسيق كلاهما بطول الأقصر.
بناء الجملة
strtr(string,from,to)
أو
strtr(string,array)
قيمه المعامل
Parameter | Description |
---|---|
string | Required. Specifies the string to translate |
from | Required (unless array is used). Specifies what characters to change |
to | Required (unless array is used). Specifies what characters to change into |
array | Required (unless to and from is used). An array containing what to change from as key, and what to change to as value |
تفاصيل تقنية
قيمة الإرجاع: | ترجع السلسلة المترجمة. إذا احتوت معلمة المصفوفة على مفتاح يمثل سلسلة فارغة ("") ، فستُرجع FALSE. |
---|---|
إصدار PHP: | 4+ |
مزيد من الأمثلة
مثال
استبدل السلسلة "Hello world" بـ "Hi earth":
<?php
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>
❮ مرجع سلسلة PHP