Does anyone have a working code that will replace special characters:
\\ + * ? [ ^ ] $ ( ) { } = ! < > | :
I have this so far, but it doesn't work for all chareacters
<?
$patterns = array("/`/", "/~/", "/!/", "/@/", "/#/", "/$/", "/%/", "/^/", "/&/", "/{/", "/}/", "/|/");
$filename = preg_replace($patterns, '', $string);
?>
replace special characters \\ + * ? [ ^ ] $ ( ) { } = ! <
Moderator: General Moderators
As there is no need for any sort of complex pattern matching, str_replace() should be quicker.
Code: Select all
<?php
$patterns = array('/', '\'', '(', ')', ':', '[', ']', '`', '~', '!', '@', '#', '$', '%', '^', '&', '{', '}', '|', '+', '*', '?');
$filename = str_replace($patterns, '', $string);
?>