1function clean($string) {
2 $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
3
4 return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
5}
1phpCopy<?php
2$mainstr = "<h2>Welcome to <b>PHPWorld</b></h2>";
3
4echo "Text before remove: \n" . $mainstr;
5
6echo "\n\nText after remove: \n" .
7 str_ireplace(array('<b>', '</b>', '<h2>', '</h2>'), '',
8 htmlspecialchars($mainstr));
9?>
10