Метод 1: использование функций strtolower() и str_replace()
$text = "Transform Text to Lowercase and Replace Space with Dash in PHP";
$lowercase = strtolower($text);
$replaced = str_replace(' ', '-', $lowercase);
echo $replaced; // Output: transform-text-to-lowercase-and-replace-space-with-dash-in-php
Метод 2: использование функции preg_replace() с регулярными выражениями
$text = "Transform Text to Lowercase and Replace Space with Dash in PHP";
$lowercase = strtolower($text);
$replaced = preg_replace('/\s+/', '-', $lowercase);
echo $replaced; // Output: transform-text-to-lowercase-and-replace-space-with-dash-in-php
Метод 3: разнесение и соединение текста
$text = "Transform Text to Lowercase and Replace Space with Dash in PHP";
$lowercase = strtolower($text);
$words = explode(' ', $lowercase);
$replaced = implode('-', $words);
echo $replaced; // Output: transform-text-to-lowercase-and-replace-space-with-dash-in-php
Метод 4. Использование функции strtr()
$text = "Transform Text to Lowercase and Replace Space with Dash in PHP";
$lowercase = strtolower($text);
$replaced = strtr($lowercase, ' ', '-');
echo $replaced; // Output: transform-text-to-lowercase-and-replace-space-with-dash-in-php
Метод 5. Использование URL-кодирования и декодирования
$text = "Transform Text to Lowercase and Replace Space with Dash in PHP";
$lowercase = strtolower($text);
$urlEncoded = urlencode($lowercase);
$replaced = str_replace('%20', '-', $urlEncoded);
echo urldecode($replaced); // Output: transform-text-to-lowercase-and-replace-space-with-dash-in-php