Jump to content

Recommended Posts

$string = "t*e*s*t";
$pattern = "/[^A-Za-zÀ-ÿ0-9\-\_\(\)\[\]\{\} ]/"; // keep all language letters, numbers, all types of brackets, spaces, hyphen, dash fullstop
$cleanStr = preg_replace($pattern, '', $string);

echo("{" . $cleanStr . "}");

I do not understand why this is not working, apart from the pattern which I know still need correcting the code is the same as code I used ages ago.  Apart from the string.

I get this error...   Parse error: syntax error, unexpected '''' (T_CONSTANT_ENCAPSED_STRING)

I am trying to remove all special characters from a string apart from all letters and accented, numbers and the usual characters allowed in a file name.

Link to comment
https://forums.phpfreaks.com/topic/315647-preg_replace-remove-special-characters/
Share on other sites

even using the original code i got from a website it still does not work, same error.  Is it the code or the pattern, both ?

Quote
$string = "t*e*s*t";
$pattern = "/[^A-Za-z0-9 ]/"; // keep all language letters, numbers, all types of brackets, spaces, hyphen, dash fullstop
//$pattern = "/[^A-Za-zÀ-ÿ0-9\-\_\(\)\[\]\{\} ]/"; // keep all language letters, numbers, all types of brackets, spaces, hyphen, dash fullstop

$cleanStr = preg_replace($pattern, '', $string);

echo("{" . $cleanStr . "}");

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.