Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> PHP

PHP 8 में str_starts_with और str_ends_with फ़ंक्शन

str_starts_with और str_ends_with फ़ंक्शन PHP 8 में जोड़े गए हैं ताकि यह जांचा जा सके कि कोई दी गई स्ट्रिंग दूसरी स्ट्रिंग से शुरू या समाप्त होती है या नहीं। यदि यह दूसरी स्ट्रिंग से शुरू और समाप्त होती है, तो यह true लौटाता है, अन्यथा false।

उदाहरण

str_starts_with('hello haystack', 'hello'); // प्रारंभ स्ट्रिंग मिली 'True'
str_starts_with('hello haystack', 'stack'); // अंत स्ट्रिंग मिली 'True'
str_starts_with('hello haystack', 'hay'); // प्रारंभ स्ट्रिंग मिली 'False'
str_starts_with('hello haystack', 'hay'); // अंत स्ट्रिंग मिली 'False'

str_starts_with() फ़ंक्शन PHP 8 में

यह फ़ंक्शन जांचता है कि क्या दी गई स्ट्रिंग स्ट्रिंग नीडल से शुरू होती है। यदि पहली स्ट्रिंग मिलती है तो यह true लौटाता है, अन्यथा false।

str_starts_with(string $haystack, string $needle): bool

उदाहरण: str_starts_with() फ़ंक्शन का उपयोग करना

<?php 
    if (str_starts_with('hellohaystack', "hello")) { 
        echo "string starts with hello"; 
    } ?>

आउटपुट

String starts with 'hello'

नोट: यदि दी गई पहली प्रारंभ स्ट्रिंग दूसरी स्ट्रिंग में नहीं मिलती है, तो यह false लौटाता है।

str_ends_with() फ़ंक्शन PHP 8 में

यह फ़ंक्शन जांचता है कि क्या दी गई स्ट्रिंग स्ट्रिंग नीडल से समाप्त होती है। यदि दी गई अंत स्ट्रिंग मिलती है तो यह true लौटाता है, अन्यथा false।

str_ends_with(string $haystack, string $needle):bool

उदाहरण: str_ends_with() फ़ंक्शन का उपयोग करना

<?php 
    if (str_ends_with('hellohaystack', "stack")) { 
        echo "string ends with stack"; 
    } ?>

आउटपुट

String ends with 'stack'
  1. - PHP में str_pad() फ़ंक्शन

    str_pad() फ़ंक्शन PHP में str_pad() फ़ंक्शन किसी स्ट्रिंग को नई लंबाई तक पैड (भरने) करने के लिए उपयोग किया जाता है। यह पैड की गई स्ट्रिंग रिटर्न करता है। सिंटैक्स str_pad(string $string, int $length, string $pad_string = , int $pad_type = STR_PAD_RIGHT): string पैरामीटर्स string - पैड की जाने वा

  1. - PHP में quoted_printable_encode() फ़ंक्शन

    quoted_printable_encode() फ़ंक्शन PHP में quoted_printable_encode() फ़ंक्शन 8-बिट स्ट्रिंग को कोटेड-प्रिंटेबल स्ट्रिंग में बदलने के लिए उपयोग किया जाता है। सिंटैक्स quoted_printable_encode(string $string): string पैरामीटर्स string - कन्वर्ट की जाने वाली 8-बिट स्ट्रिंग रिटर्न वैल्यू quoted_print

  1. - PHP में quoted_printable_decode() फ़ंक्शन

    quoted_printable_decode() फ़ंक्शन PHP में quoted_printable_decode() फ़ंक्शन कोटेड-प्रिंटेबल स्ट्रिंग को 8-बिट स्ट्रिंग में बदलने के लिए उपयोग किया जाता है। सिंटैक्स quoted_printable_decode(string $string): string पैरामीटर्स string - इनपुट स्ट्रिंग रिटर्न वैल्यू quoted_printable_decode() फ़ंक्शन