تعريف الوظائف
تبدأ مع () تبدأ الوظيفة مع ($haystack، $needle) { $length = strlen($needle); return substr($haystack, 0, $length) === $needle;
function startsWith($haystack, $needle) { $length = strlen($needle); return substr($haystack, 0, $length) === $needle; }endsWith()
function endWith($haystack, $needle) { $length = strlen($needle); إذا (! طول $) { عودة صحيحة؛ } return substr($haystack, -$length) === $needle;
function endsWith($haystack, $needle) { $length = strlen($needle); if (!$length) { return true; } return substr($haystack, -$length) === $needle; }
مثال للاستخدام
$str = '|apples}'; يبدأ الصدى مع($str, '|'); // إرجاع صحيح صدى ينتهي مع($str, '}'); // تُرجع صحيحًا
$str = '|apples}'; echo startsWith($str, '|'); // Returns true echo endsWith($str, '}'); // Returns true
PHP 8.0 وما فوق
تنصل: جميع الموارد المقدمة هي جزئيًا من الإنترنت. إذا كان هناك أي انتهاك لحقوق الطبع والنشر الخاصة بك أو الحقوق والمصالح الأخرى، فيرجى توضيح الأسباب التفصيلية وتقديم دليل على حقوق الطبع والنشر أو الحقوق والمصالح ثم إرسالها إلى البريد الإلكتروني: [email protected]. سوف نتعامل مع الأمر لك في أقرب وقت ممكن.
Copyright© 2022 湘ICP备2022001581号-3