Remove spaces from the beginning and end of a string and remove dashes

@return mixed
544644
public static function dashless(string $s)
	{
		$s = trim($s);
		$s = self::replace($s, '#\-#', '');

		return $s;
	}
177032
private function removeWhitespace(): void
    {
        $string = preg_replace('/ {2,}/', Tokens::SPACE, $this->normalisedString);
        $lines = [];

        foreach (explode(Tokens::LINE_FEED, $string) as $line) {
            if ('' !== $line = trim($line)) {
                $lines[] = $line;
            }
        }
        $this->normalisedString = implode(Tokens::LINE_FEED, $lines);
    }
880048
public function normalizePath()
    {
        if (!$this->path || $this->path == '/' || $this->path == '*') {
            return $this;
        }

        // Replace // and /./ with /
        $this->path = str_replace(array('/./', '//'), '/', $this->path);

        // Remove dot segments
        if (strpos($this->path, '..') !== false) {

            // Remove trailing relative paths if possible
            $segments = $this->getPathSegments();
            $last = end($segments);
            $trailingSlash = false;
            if ($last === '') {
                array_pop($segments);
                $trailingSlash = true;
            }

            while ($last == '..' || $last == '.') {
                if ($last == '..') {
                    array_pop($segments);
                    $last = array_pop($segments);
                }
                if ($last == '.' || $last == '') {
                    $last = array_pop($segments);
                }
            }

            $this->path = implode('/', $segments);
            if ($trailingSlash) {
                $this->path .= '/';
            }
        }

        return $this;
    }
136394
function cleanUpTitle(rawTitleString) {
    /*dashChar is most commonly the dash of the title string, or a
  the first repeating character surrounding the title */
    var dashChar = rawTitleString.charAt(0);
    //beginning and ending index of the dash
    var dashBegIndex = 0;
    var dashEndIndex = rawTitleString.lastIndexOf(dashChar);

    //loop through to find indicies without continous dashes
    while (rawTitleString.charAt(dashBegIndex) === (dashChar || '\n')) {
        dashBegIndex++;
    }
    while (rawTitleString.charAt(dashEndIndex) === (dashChar || '\n')) {
        dashEndIndex--;
    }

    var titleString = rawTitleString.slice(dashBegIndex + 1, dashEndIndex - 1);
    titleString = trimStringEnds(titleString, ['\n', '-']);
    return titleString;
}
1194163
public function getExtrasDDLWithDelimiter()
    {
        $ddls = $this->getExtrasDDL();
        $start = "DELIMITER {$this->delimiter}";
        $end = 'DELIMITER ;';

        $newDdls = [];

        foreach ($ddls as $idx => $ddl) {
            $newDdls[] = $start;
            if (!preg_match('/;$/', $ddl)) {
                $newDdls[] = $ddl . ' ' . $this->delimiter;
            } else {
                $newDdls[] = preg_replace('/;$/', $this->delimiter, $ddl);
            }
            $newDdls[] = $end;
        }

        return implode(PHP_EOL, $newDdls) . PHP_EOL . $end . PHP_EOL;
    }
1179186
static function CorrectSpaces($text)
    {
        $chars = '!,;.?:';
        $charArray = str_split($chars);
        foreach ($charArray as $char)
        {
            $text = Str::Replace($char, $char . ' ', $text);
        }
        return  self::RemoveMultipleSpaces($text);
    }
756196
protected function _initDetab() {
	
		if (function_exists($this->utf8_strlen)) {
			return;
		}

		$this->utf8_strlen = function($text) {
			return preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', $text, $m);
		};
	}
685882
public function getNamespace()
    {
        $class       = array();
        $inNamespace = false;

        foreach ($this->tokenlist as $key => $token) {
            if (T_NAMESPACE === $token[0]) {
                $inNamespace = true;
                continue;
            }
            if (T_STRING === $token[0] && $inNamespace) {
                $class[] = $token[1];

            }
            if (';' === $token && $inNamespace) {
                return $class;
            }
        }

        return array();
    }
1143539
private function trimSpecialsChars($s)
    {
        if (count($this->getNotReplacedChars()) == 0) {
            $reg = '~[^-a-z0-9_]+~';
        } else {
            $reg = '~[^-a-z0-9_' . implode('', $this->getNotReplacedChars()) .']+~';
        }
        return preg_replace($reg, '', $s);
    }
876771
public function sanitizeFilename()
	{
		// Regex for replacing special chars
		$filename = $this->filename;
		$filename = preg_replace('/\s+/', '_', $filename);
		$filename = preg_replace('/[^a-z1-9\.\-\_]/i', '', $filename);
		// removes any dots except the last one.
		$filename = preg_replace('/\.(?=.*?\.)/', '', $filename);
		$this->filename = $filename;

		return $this;
	}
938227
public function normalize() {
		// remove whitespace from the beginning
		$this->str = ltrim($this->str);

		// ensure that there is exactly one forward slash at the beginning
		$this->str = '/'.ltrim($this->str, '/');

		// remove whitespace from the end
		$this->str = rtrim($this->str);


		return $this;
	}
653744
function getFormattedNamespaces() {
		$ns = $this->getNamespaces();
		foreach ( $ns as $k => $v ) {
			$ns[$k] = strtr( $v, '_', ' ' );
		}
		return $ns;
	}
821546
public function getFullNameRevAttribute()
    {
        $first = [];
        $first[] = $this->first_name  ?: '';
        $first[] = $this->middle_name ?: '';

        $names = [];
        $names[] = $this->last_name ?: '';
        $names[] = implode(' ', array_filter($first));

        return trim(implode(', ', array_filter($names)));
    }
1318490
public function normalize()
    {
        $data = $this->get();
        if (is_array($data)) {
            $data = implode($this->separator, $data);
        }
        $data = trim($data, $this->separator);
        if (!$data) {
            $data = null;
        }

        if (get_magic_quotes_gpc()) {
            $this->set(stripslashes($data));
        } else {
            $this->set($data);
        }

        return parent::normalize();
    }
361677
function slugify()
    {
        $text = (string) $this;

        // replace non letter or digits by -
        $text = preg_replace('~[^\pL\d]+~u', '-', $text);

        // transliterate
        $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

        // remove unwanted characters
        $text = preg_replace('~[^-\w]+~', '', $text);

        // trim
        $text = trim($text, '-');

        // remove duplicate -
        $text = preg_replace('~-+~', '-', $text);

        // lowercase
        $text = strtolower($text);

        if (empty($text))
            return 'n-a';

        return new self($text);
    }
701737
public static function dashToCamelCase($string)
    {
        $result = '';
        $urlPart = explode('-', $string);
        foreach ($urlPart as $word) {
            $result .= ucfirst(strtolower($word));
        }
        return $result;
    }
344938
private function stripWhitespace($source)
    {
        // Verificar se token_get_all existe
        if (! function_exists('token_get_all')) {
            return $source;
        }

        $output = '';
        foreach (token_get_all($source) as $token) {
            if (is_string($token)) {
                $output .= $token;
            } elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
                $output .= str_repeat("\n", substr_count($token[1], "\n"));
            } elseif (T_WHITESPACE === $token[0]) {
                // reduce wide spaces
                $whitespace = preg_replace('{[ \t]+}', ' ', $token[1]);
                // normalize newlines to \n
                $whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
                // trim leading spaces
                $whitespace = preg_replace('{\n +}', "\n", $whitespace);
                $output .= $whitespace;
            } else {
                $output .= $token[1];
            }
        }

        return $output;
    }