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}
1<?php
2
3$string = 'foo';
4
5if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string))
6{
7 // one or more of the 'special characters' found in $string
8}
9
1/* EXAMPLE: <p>Bed & Breakfast</p> --> <p>Bed & Breakfast</p>
2 & &
3 " " (unless ENT_NOQUOTES is set)
4 ' ' or ' (ENT_QUOTES must be set)
5 < <
6 > > */
7
8<?php
9$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
10echo $new; // <a href='test'>Test</a>
11?>