Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Remove Special Characters


GiantSquid - 12:59 am on Feb 18, 2012 (gmt 0)


You could use something like this. If there are only a few characters you are concerned about, you could use a str_replace for each one e.g.

$metastring = str_replace("'", '', $metastring);
$metastring = str_replace("&", '', $metastring);


Otherwise use a preg_replace with Regex like this which would remove all characters except letters, numbers, periods and hyphens

$newmetastring = preg_replace('/[^A-Za-z0-9\s.\s-]/','',$metastring);


Thread source:: http://www.webmasterworld.com/php/4417500.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com