如何在 preg_match 和 php 中允许斜线 /

how to allow a slash / in preg_match with php

要仅过滤 a-zA-Z0-9 的输入,我使用此行:

preg_match('/^[a-zA-Z0-9]+$/', $_POST['copyfile-destination'])

我需要更改什么才能允许使用斜杠 /

您需要对其进行转义或使用其他分隔符(例如 # 而不是 /)

preg_match('/^[a-zA-Z0-9\/]+$/', $_POST['copyfile-destination'])

preg_match('#^[a-zA-Z0-9/]+$#', $_POST['copyfile-destination'])