Strings section
Slugify
startsWith
endsWith
clean
xssClean
convertToUtf8
sanitizeOutput
escapeXss
stripAllWhitespace
truncateStringWithoutCuttingWord
require_once 'Strings.php';
$strings = new Strings();
// Example usage:
$string = " Hello, World! Welcome to programming with PHP. ";
Converts a string into a URL-friendly slug, supporting Turkish and other languages.
// Slugify
echo "Slugified: " . Strings::slugify($string) . "\n";
Checks if a string starts with a specific substring.
// Starts with
echo "Starts with 'Hello': " . (Strings::startsWith($string, "Hello") ? "Yes" : "No") . "\n";
Checks if a string ends with a specific substring.
// Ends with
echo "Ends with 'PHP.': " . (Strings::endsWith($string, "PHP.") ? "Yes" : "No") . "\n";
Cleans a string by removing extra whitespace and non-printable characters.
// Clean
echo "Cleaned: " . Strings::clean($string) . "\n";
Cleans a string to prevent XSS (Cross-Site Scripting) attacks by stripping dangerous HTML tags.
// XSS Clean
$maliciousString = "<script>alert('XSS');</script>";
echo "XSS Cleaned: " . Strings::xssClean($maliciousString) . "\n";
Converts a string from its detected encoding to UTF-8
// Encoding conversion
$originalString = "Some text with potential encoding issues";
$utf8String = Strings::convertToUtf8($originalString);
echo "UTF-8 Converted: $utf8String\n";
Sanitizes a string for output by removing HTML tags and escaping special characters
// Output sanitization
$dirtyInput = "<script>alert('XSS');</script>Hello, World!";
$cleanOutput = Strings::sanitizeOutput($dirtyInput);
echo "Sanitized Output: $cleanOutput\n";
Escapes special characters to prevent XSS vulnerabilities
// XSS Escaping
$xssInput = "& \"' < >";
$escapedInput = Strings::escapeXss($xssInput);
echo "XSS Escaped: $escapedInput\n";
Removes all whitespace characters from a string
// Whitespace stripping
$stringWithSpaces = " Hello World \n\t";
$strippedString = Strings::stripAllWhitespace($stringWithSpaces);
echo "Whitespace Stripped: $strippedString\n";
Truncates a string to a specified length without cutting a word
// String truncation
$longString = "This is a very long string that needs to be truncated without cutting words";
$truncatedString = Strings::truncateStringWithoutCuttingWord($longString, 30);
echo "Truncated String: $truncatedString\n";