i use preg replace since my column database does not support "strange letters" but after regex i need keep "/", in this code bellow "/" is always missing in code bellow i need to get all letter complete
<?php
$jurnalName = "TL 110/90-12 K93-N02 AHM ";
$name = htmlspecialchars(htmlentities($jurnalName));
$name = preg_replace('/[^A-Za-z0-9|\- ]/', '', $name);
var_dump($name);
the result is always "TL 11090-12 K93-N02 AHM " what i expecting is complete "TL 110/90-12 K93-N02 AHM "
CodePudding user response:
Add / to the list of chars you want to keep
<?php
$jurnalName = "TL 110/90-12 K93-N02 AHM ";
$name = htmlspecialchars(htmlentities($jurnalName));
$name = preg_replace('/[^A-Za-z0-9|\-\s\ \/]/', '', $name);
var_dump($name);
(I also changed the space for \s and scaped the plus , its optional here but I think its a good practice for characters that have spetial meaning inside regex