php变量,以便在显示结果的HTML表单值中清除URL


php variable to make clean URL in a HTML form value that show the result

我如何制作一个html表单,你可以将信息放在输入中,并在下一次输入中在一个干净的URL中给你数据的结果,这就是我的进展,函数的工作原理,我需要第一个值(slugit)进入函数,我留下代码,如果有人能帮助我,我会很高兴:

<form action="test.php" method="post">              
  <input type="text" name="name"/> <!--put your first value (slugit) --> 
  <input type="submit" class="btn btn-success" value="Run">
</form>
<?php
setlocale(LC_ALL, 'en_US.UTF8');
function slugit($str, $replace=array(), $delimiter='-') {
    if ( !empty($replace) ) {
        $str = str_replace((array)$replace, ' ', $str);
    }
    $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    $clean = preg_replace("/[^a-zA-Z0-9'/_|+ -]/", '', $clean);
    $clean = strtolower(trim($clean, '-'));
    $clean = preg_replace("/['/_|+ -]+/", $delimiter, $clean);
    return $clean;
}
$slug = slugit("esto es untést ed manejoñol132_sd. dsf-asd</");
echo $slug;
?>
<label>Result:</label>
<input type="text" name="slug_prod" id="slug_prod" value="<?php echo $slug; ?>">

他们尝试以这种方式使用

  <form action="test.php" method="post">              
  <input type="text" name="name" value="" />
  <input type="submit" class="btn btn-success" value="Run">
</form>
<?php
setlocale(LC_ALL, 'en_US.UTF8');
function slugit($str, $replace=array(), $delimiter='-') {
        $string = strtolower($str);
        //Strip any unwanted characters
        $string = preg_replace("/[^a-z0-9_'s-]/", "", $string);
        //Clean multiple dashes or whitespaces
        $string = preg_replace("/['s-]+/", " ", $string);
        //Convert whitespaces and underscore to dash
        $string = preg_replace("/['s_]/", "-", $string);
        return $string;
}
$test = slugit($_POST['name']);
$slug = $test;
?>
<label>Result:</label>
<input type="text" class="form-control" name="slug_prod" id="slug_prod" value="<?php echo $slug; ?>">