Function to etract email from text

@access	public
@param   string  $text
@return	array
504348
public static function extractEmail($text)
    {
        $matches    = array();
        $pattern	= "/(?:[a-z0-9!#$%&'*+=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/";

        // Devuelve un array de dos dimensiones
        preg_match_all($pattern, $text, $matches); //find matching pattern

        if(count($matches) > 0)
            $matches = $matches[0];

        return $matches;
    }
604619
protected function parseAttr($text)
    {
        $atts = [];

        $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';

        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);

        if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) )
        {
            foreach ($match as $m)
            {
                if (!empty($m[1]))
                    $atts[strtolower($m[1])] = stripcslashes($m[2]);
                elseif (!empty($m[3]))
                    $atts[strtolower($m[3])] = stripcslashes($m[4]);
                elseif (!empty($m[5]))
                    $atts[strtolower($m[5])] = stripcslashes($m[6]);
                elseif (isset($m[7]) and strlen($m[7]))
                    $atts[] = stripcslashes($m[7]);
                elseif (isset($m[8]))
                    $atts[] = stripcslashes($m[8]);
            }
        }
        else
        {
            $atts = ltrim($text);
        }

        return $atts;
    }
1233149
public function getMessageLines($text)
    {
        $message = $text;
        $wrapLength = 40;
        // wrap the message to max chars
        $message = wordwrap($message, $wrapLength - 2);
        // split into array of lines
        return explode("\n", $message);
    }
765314
protected function doAutoLinks($text)
    {
        if(!$this->features['auto_mailto'])
        {
            return preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
            array(&$this, '_doAutoLinks_url_callback'), $text);
        }

        return parent::doAutoLinks($text);
    }
149283
function leetify( $text )
    {
        $text = preg_replace( "/to/", "2", $text );
        $text = preg_replace( "/for/", "4", $text );
        $text = preg_replace( "/ate/", "8", $text );
        $text = preg_replace( "/you/", "u", $text );
        $text = preg_replace( array( "/l/",
                                     "/e/",
                                     "/o/",
                                     "/a/",
                                     "/t/" ),
                              array( "1",
                                     "3",
                                     "0",
                                     "4",
                                     "7" ), $text );
        return $text;
    }
879997
static private function leetify( $text )
    {
        $searchMap = array( '/to/i', '/for/i', '/ate/i', '/your/i', '/you/i', '/l/i', '/e/i', '/o/i', '/a/i', '/t/i' );
        $replaceMap = array( '2', '4', '8', 'ur', 'u', '1', '3', '0', '4', '7' );

        $textBlocks = preg_split( '/(%[^ ]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
        $newTextBlocks = array();
        foreach ( $textBlocks as $text )
        {
            if ( strlen( $text ) && $text[0] == '%' )
            {
                $newTextBlocks[] = (string) $text;
                continue;
            }
            $text = preg_replace( $searchMap, $replaceMap, $text );

            $newTextBlocks[] = (string) $text;
        }
        $text = implode( '', $newTextBlocks );
        return $text;
    }
1163588
public function tokenize(string $text) : array
    {
        $pattern =
'/(\[
    \/?
    \w+
    (?:
        =
        (?:
            "[^"]+"
            |\'[^\']+\'
            |[^]]+
        )
    )?
\])/x';

        $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE;
        $tokens = preg_split($pattern, $text, -1, $flags);
        $tokens = array_map(function ($text) use ($pattern) {
            $matches = [];
            if (preg_match($pattern, $text, $matches)) {
                $token = new TagToken($text);

                // Fallback to a text token if tag is not valid.
                if (!$this->validateTagToken($token)) {
                    return new TextToken($text);
                }

                return $token;
            } else {
                return new TextToken($text);
            }
        }, $tokens);
        return $this->processRawContentTagTokens($tokens);
    }
276128
public function readTab($text) {
		$pieces = explode("\n", $text);
		$result = [];
		foreach ($pieces as $piece) {
			$tmp = explode("\t", trim($piece, "\r\n"));
			$result[] = $tmp;
		}
		return $result;
	}
770588
public static function strtotitle($text) {
        if (empty($text)) {
            return $text;
        }

        if (function_exists('mb_convert_case')) {
            return mb_convert_case($text, MB_CASE_TITLE, 'UTF-8');
        }

        $text = self::strtolower($text);
        $words = explode(' ', $text);
        foreach ($words as $i=>$word) {
            $length = self::strlen($word);
            if (!$length) {
                continue;

            } else if ($length == 1) {
                $words[$i] = self::strtoupper($word);

            } else {
                $letter = self::substr($word, 0, 1);
                $letter = self::strtoupper($letter);
                $rest   = self::substr($word, 1);
                $words[$i] = $letter.$rest;
            }
        }
        return implode(' ', $words);
    }
1223015
private function parseInlineHtml($text)
	{
		if (strpos($text, '>') !== false) {
			// convert a name markers to \labels
			if (preg_match('~^<((a|span)) (name|id)="(.*?)">.*?</\1>~i', $text, $matches)) {
				return [
					['label', 'name' => str_replace('#', '::', $this->labelPrefix . $matches[4])],
					strlen($matches[0])
				];
			}
		}
		return [['text', '<'], 1];
	}
265025
private function decodeContentTypesFromText($text)
    {
        $contenttypes = [];

        if ((substr($text, 0, 1) == '(') &&
            (substr($text, -1) == ')')
        ) {
            $contenttypes = explode(',', substr($text, 1, -1));
        } else {
            $contenttypes[] = $text;
        }

        $instance = $this;
        $contenttypes = array_map(
            function ($name) use ($instance) {
                $ct = $instance->getContentType($name);

                return $ct['slug'];
            },
            $contenttypes
        );

        return $contenttypes;
    }
543959
protected function splitText($text)
    {
        $punctuations = preg_quote(implode('', $this->punctuations), '/');

        $text = preg_replace('/([^\p{Han}\s'.$punctuations.']+)/u', "\t\t\t$1\t\t", $text);

        $array = [];

        foreach (preg_split('/\t\t/u', $text, -1, PREG_SPLIT_NO_EMPTY) as $item) {
            $array[] = ("\t" === $item[0])
                ? substr($item, 1)
                : preg_split('//u', $item, -1, PREG_SPLIT_NO_EMPTY);
        }

        return $this->flatten($array);
    }
153037
public static function find(string $text) : Header
    {
        $matches = [];
        $parent = new Header();
        if (\preg_match_all(self::HEADERS_REGEX, $text, $matches, PREG_OFFSET_CAPTURE)) {
            foreach ($matches[0] as $index => $match) {
                $parent->append(new Header((int)$match[1], \strlen($match[0]), (int)$matches[1][$index][0], $matches[2][$index][0]));
            }
        }
        return $parent;
    }
124890
private function processText($text)
    {
        // verify if content is a string otherwhise just return the original provided content
        if (!is_string($text) || empty($text)) {
            return $text;
        }
        // find all tags based on the REGEX expression
        preg_match_all(static::REGEX, $text, $results, PREG_SET_ORDER);
        // foreach all the results matches the regex
        foreach ($results as $row) {
            // When value is empty (can be caused by using `link[]` we have to skip this item.
            if (empty($row['value'])) {
                continue;
            }
            // extract tag name from regex
            $tag = $row['function'];
            if ($this->hasTag($tag)) {
                $replace = $this->parseTag($tag, $row);
                $text = preg_replace('/'.preg_quote($row[0], '/').'/mi', $replace, $text, 1);
            }
        }
        
        return $text;
    }
952876
public function apply($text)
    {
        $setCodes = array();
        $unsetCodes = array();
        if (null !== $this->foreground) {
            $setCodes[] = $this->foreground['set'];
            $unsetCodes[] = $this->foreground['unset'];
        }
        if (null !== $this->background) {
            $setCodes[] = $this->background['set'];
            $unsetCodes[] = $this->background['unset'];
        }
        if (count($this->options)) {
            foreach ($this->options as $option) {
                $setCodes[] = $option['set'];
                $unsetCodes[] = $option['unset'];
            }
        }
        if (0 === count($setCodes)) {
            return $text;
        }
        return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
    }
1089580
public function replace($text)
    {
        preg_match_all($this->pattern, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
        $delta = 0;
        foreach ($matches as $match)
        {
            $stringsOnly = array();
            foreach ($match as $info)
            {
                $stringsOnly []= $info[0];
            }
            $replace = call_user_func($this->callback, $stringsOnly);
            if (false === $replace || null === $replace)
            {
                continue;
            }

            $text = substr_replace($text, $replace, $match[0][1] + $delta, strlen($match[0][0]));
            $delta += strlen($replace) - strlen($match[0][0]);
        }

        return $text;
    }
977451
public function parse($text)
    {
        $names = $this->names
            ? implode('|', array_map('preg_quote', $this->names))
            : RegexBuilderUtility::buildNameRegex();
        $regex = str_replace('<NAMES>', $names, static::$shortcodeRegex);
        preg_match_all($regex, $text, $matches, PREG_OFFSET_CAPTURE);

        $shortcodes = array();
        $count = count($matches[0]);
        for($i = 0; $i < $count; $i++) {
            $name = $matches[2][$i][0];
            $parameters = static::parseParameters($matches[3][$i][0]);
            $content = $matches[5][$i][1] !== -1 ? $matches[5][$i][0] : null;
            $match = $matches[0][$i][0];
            $offset = mb_strlen(substr($text, 0, $matches[0][$i][1]), 'utf-8');

            $shortcode = new Shortcode($name, $parameters, $content, null);
            $shortcodes[] = new ParsedShortcode($shortcode, $match, $offset);
        }

        return $shortcodes;
    }