Horde_Mime_Part::_findBoundary PHP Method

_findBoundary() protected static method

Find the location of the next boundary string.
protected static _findBoundary ( string $text, integer $pos, string $boundary, integer $end = null ) : array
$text string The text to search.
$pos integer The current position in $text.
$boundary string The boundary string.
$end integer If set, return after matching this many boundaries.
return array Keys are the boundary number, values are an array with two elements: 'start' and 'length'.
    protected static function _findBoundary($text, $pos, $boundary, $end = null)
    {
        $i = 0;
        $out = array();
        $search = "--" . $boundary;
        $search_len = strlen($search);
        while (($pos = strpos($text, $search, $pos)) !== false) {
            /* Boundary needs to appear at beginning of string or right after
             * a LF. */
            if ($pos != 0 && $text[$pos - 1] != "\n") {
                continue;
            }
            if (isset($out[$i])) {
                $out[$i]['length'] = $pos - $out[$i]['start'] - 1;
            }
            if (!is_null($end) && $end == $i) {
                break;
            }
            $pos += $search_len;
            if (isset($text[$pos])) {
                switch ($text[$pos]) {
                    case "\r":
                        $pos += 2;
                        $out[++$i] = array('start' => $pos);
                        break;
                    case "\n":
                        $out[++$i] = array('start' => ++$pos);
                        break;
                    case '-':
                        return $out;
                }
            }
        }
        return $out;
    }