I have a regular expression that strips everything but letters. numbers, and periods. How do I also add foreslashes to it?
$targetFile = preg_replace('/[^A-Za-z0-9-.]/', '', $targetFileDirty);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can escape the foreslash by putting a backslash before it –
$targetFile = preg_replace('/[^A-Za-z0-9-.\/]/', '', $targetFileDirty);Alternatively, and perhaps better, you can use different delimiters instead, e.g.
$targetFile = preg_replace('#[^A-Za-z0-9-./]#', '', $targetFileDirty);