Hướng dẫn find string between two characters in php - tìm chuỗi giữa hai ký tự trong php

Phần lớn các câu trả lời ở đây không trả lời phần đã được chỉnh sửa, tôi đoán chúng đã được thêm vào trước đó. Nó có thể được thực hiện với Regex, như một câu trả lời đề cập. Tôi đã có một cách tiếp cận khác.


Hàm này tìm kiếm $ String và tìm chuỗi đầu tiên giữa các chuỗi $ bắt đầu và $ end, bắt đầu ở vị trí bù $. Sau đó, nó cập nhật vị trí bù $ để chỉ vào đầu kết quả. Nếu $ bao gồm các nhà là đúng, nó bao gồm các dấu phân cách trong kết quả.first string between $start and $end strings, starting at $offset position. It then updates the $offset position to point to the start of the result. If $includeDelimiters is true, it includes the delimiters in the result.

Nếu không tìm thấy chuỗi $ start hoặc $ end, nó sẽ trả về null. Nó cũng trả về null nếu $ chuỗi, $ start hoặc $ end là một chuỗi trống.

function str_between(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?string
{
    if ($string === '' || $start === '' || $end === '') return null;

    $startLength = strlen($start);
    $endLength = strlen($end);

    $startPos = strpos($string, $start, $offset);
    if ($startPos === false) return null;

    $endPos = strpos($string, $end, $startPos + $startLength);
    if ($endPos === false) return null;

    $length = $endPos - $startPos + ($includeDelimiters ? $endLength : -$startLength);
    if (!$length) return '';

    $offset = $startPos + ($includeDelimiters ? 0 : $startLength);

    $result = substr($string, $offset, $length);

    return ($result !== false ? $result : null);
}

Hàm sau đây tìm thấy tất cả các chuỗi nằm giữa hai chuỗi (không có sự chồng chéo). Nó yêu cầu chức năng trước đó và các đối số là như nhau. Sau khi thực hiện, $ Offset chỉ vào đầu chuỗi kết quả được tìm thấy cuối cùng.all strings that are between two strings (no overlaps). It requires the previous function, and the arguments are the same. After execution, $offset points to the start of the last found result string.

function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
{
    $strings = [];
    $length = strlen($string);

    while ($offset < $length)
    {
        $found = str_between($string, $start, $end, $includeDelimiters, $offset);
        if ($found === null) break;

        $strings[] = $found;
        $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
    }

    return $strings;
}

Examples:

str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar') cho [' 1 ', ' 3 '].

str_between_all('foo 1 bar 2', 'foo', 'bar') cho [' 1 '].

function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
{
    $strings = [];
    $length = strlen($string);

    while ($offset < $length)
    {
        $found = str_between($string, $start, $end, $includeDelimiters, $offset);
        if ($found === null) break;

        $strings[] = $found;
        $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
    }

    return $strings;
}
0 cho [' 1 ', ' 3 '].

function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
{
    $strings = [];
    $length = strlen($string);

    while ($offset < $length)
    {
        $found = str_between($string, $start, $end, $includeDelimiters, $offset);
        if ($found === null) break;

        $strings[] = $found;
        $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
    }

    return $strings;
}
2 cho
function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
{
    $strings = [];
    $length = strlen($string);

    while ($offset < $length)
    {
        $found = str_between($string, $start, $end, $includeDelimiters, $offset);
        if ($found === null) break;

        $strings[] = $found;
        $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
    }

    return $strings;
}
3.

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc
    Examples: 
     

    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"

    Bàn luận Firstly you have to find the ending position of the start word. Then find the starting position of the ending word after that return the substring between those indexes. 
    Below program illustrate the approach:
    Program: 
     

    PHP

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    4

    str_between_all('foo 1 bar 2', 'foo', 'bar')2

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    6
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    7
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    0
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    2222

    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    4

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5[' 1 ']2
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    7[' 1 ']4
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    0
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
     to geeks
    3

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    01
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    022____922

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    05[' 1 ']2
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    7[' 1 ']4
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    9__2222222

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5
    , how are 
    5
    , how are 
    6
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    9
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    6
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
     $arr=explode(separator, string).
    22

    str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')4

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    7str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')7str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')8

    str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')9 [' 1 ', ' 3 ']0

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9[' 1 ', ' 3 ']3
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9[' 1 ', ' 3 ']5
     to geeks
    3

    [' 1 ', ' 3 ']7 str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')9str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')8

    str_between_all('foo 1 bar 2', 'foo', 'bar')0

    Output:   
     

     to geeks

    Phương pháp 2: Sử dụng hàm Explode (). Hàm bùng nổ phân tách chuỗi đã cho trên cơ sở tham số được cung cấp, tức là bộ phân cách. & Nbsp; cú pháp: & nbsp; & nbsp; Using the explode() function. The explode function splits the given string on the basis of the parameter provided i.e. the separator. 
    Syntax: 
     

     $arr=explode(separator, string).

    Điều này sẽ trả về một mảng sẽ chứa chuỗi phân chia trên cơ sở phân tách. & Nbsp; & nbsp;
     

    • Chia danh sách trên cơ sở từ bắt đầu.
    • Trong mảng trả về, chỉ mục thứ 2 sẽ chứa các từ sau từ bắt đầu.
    • Trong chuỗi được cung cấp theo bước 2 nếu chúng ta lại chia nó trên cơ sở từ kết thúc thì giá trị ở chỉ mục đầu tiên sẽ là chuỗi giữa từ bắt đầu và từ kết thúc.

    Dưới đây chương trình minh họa cách tiếp cận & nbsp; chương trình: & nbsp; & nbsp;
    Program: 
     

    PHP

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    4

    str_between_all('foo 1 bar 2', 'foo', 'bar')2

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    6
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    7
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    0
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    2222

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5[' 1 ']2
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    7[' 1 ']4
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    9
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    0
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
     to geeks
    3

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    01
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    022____922

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    05[' 1 ']2
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    7[' 1 ']4
    Input:$string="hey, How are you?"
    If we need to extract the substring between 
    "How" and "you" then the output should be are
     
    Output:"Are"
    
    Input:Hey, Welcome to GeeksforGeeks
    If we need to get the substring between Welcome and 
    for then it should be to geeks as for lies within GeeksforGeeks.
    
    Output:" to geeks"
    9__2222222

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    05
    , how are 
    5 [' 1 ']2
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    17

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')4

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    5
    , how are 
    5
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    222str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')8

    str_between_all('foo 1 bar 2', 'foo', 'bar')2str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')4

    str_between_all('foo 1 bar 2', 'foo', 'bar')2

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    28

    str_between_all('foo 1 bar 2', 'foo', 'bar')2

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    30
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    31

    str_between_all('foo 1 bar 2', 'foo', 'bar')2

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    33
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    34

    str_between_all('foo 1 bar 2', 'foo', 'bar')2str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')9 [' 1 ', ' 3 ']0

    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    8
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    30
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    9
    function str_between_all(string $string, string $start, string $end, bool $includeDelimiters = false, int &$offset = 0): ?array
    {
        $strings = [];
        $length = strlen($string);
    
        while ($offset < $length)
        {
            $found = str_between($string, $start, $end, $includeDelimiters, $offset);
            if ($found === null) break;
    
            $strings[] = $found;
            $offset += strlen($includeDelimiters ? $found : $start . $found . $end); // move offset to the end of the newfound string
        }
    
        return $strings;
    }
    
    33
     to geeks
    3

    str_between_all('foo 1 bar 2', 'foo', 'bar')2[' 1 ', ' 3 ']7 str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')9str_between_all('foo 1 bar 2 foo 3 bar', 'foo', 'bar')8

    str_between_all('foo 1 bar 2', 'foo', 'bar')0

    Output:   
     

    , how are 

    Làm thế nào để có được dữ liệu giữa hai chuỗi trong PHP?

    Phương pháp 1: Đầu tiên bạn phải tìm vị trí kết thúc của từ bắt đầu ...
    Chia danh sách trên cơ sở từ bắt đầu ..
    Trong mảng trả về, chỉ mục thứ 2 sẽ chứa các từ sau từ bắt đầu ..

    Làm thế nào để bạn có được một chuỗi giữa?

    Chuỗi kiểm tra Chuỗi kiểm tra (67) từ đó bạn cần lấy chuỗi được lồng ở giữa hai chuỗi ...
    Chuỗi str = "Chuỗi kiểm tra (67) và (77)", open = "(", đóng = ")" ;.
    Chuỗi chuỗi con = str ..

    Strstr PHP là gì?

    Hàm strstr () tìm kiếm sự xuất hiện đầu tiên của một chuỗi bên trong chuỗi khác.Lưu ý: Hàm này an toàn cho nhị phân.Lưu ý: Hàm này là nhạy cảm trường hợp.Đối với tìm kiếm không nhạy cảm trường hợp, sử dụng hàm stristr ().searches for the first occurrence of a string inside another string. Note: This function is binary-safe. Note: This function is case-sensitive. For a case-insensitive search, use stristr() function.

    Làm cách nào để trích xuất một chuỗi giữa hai ký tự trong Python?

    Trích xuất chuỗi con giữa hai điểm đánh dấu bằng phương thức Split () Phương thức tiếp theo mà chúng ta sẽ sử dụng là phương thức phân chia ngôn ngữ lập trình python, để trích xuất một chuỗi con nhất định giữa hai điểm đánh dấu.Phương thức Split () trong Python chia chuỗi đã cho từ một dấu phân cách đã cho và trả về một danh sách các chuỗi con được chia.split() method Next method that we will be using is the split() method of Python Programming language, to extract a given substring between two markers. The split() method in python splits the given string from a given separator and returns a list of splited substrings.