Skip to content
Advertisement

Ignore specific character: –

I want to ignore a specific character using php. So when a user adds this character in the textbox. the php scripts filters it out first. I tried something and came up with this:

<?php
    $datetogoto = $_GET['datetogoto'];
    $pattern = '-';
    $replace = '';
    preg_replace($pattern, $replace, $datetogoto);
    header('Location: ../index.php?newsdate='.$datetogoto);
?>

So what it wrong with this code?

Advertisement

Answer

Can you try using str_replace

$datetogoto = $_GET['datetogoto'];

$datetogoto = str_replace("-","", $datetogoto);

Ref: http://us1.php.net/str_replace

Or , if you want get date format whatever you sent in query string, then use urlencode()

header('Location: ../index.php?newsdate='.urlencode($datetogoto));
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement