title: PHP hyphens problem when using a variable
body: <p>My website is a search engine.</p>
  
  <p>In my .htaccess file I have:</p>
  
  <pre><code>RewriteRule ^news/(.*)\.html$ /results/news.php?name=$1
  </code></pre>
  
  <p>And my link structure is <code>/news/what-is-up.html</code> using hyphens.</p>
  
  <p>When I search for <strong>/results/news.php?name=hello world</strong> I get different results than when I use <strong>/news/hello-world.html</strong></p>
  
  <p>It seems that the search is searching for <code>hello-world</code> using hypens instead of spaces, I could easily solve it using a <code>+</code> sign but I want to use hyphens. Does anyone know how to do it?</p>
  
  <p>This is the code I use for converting the name variable into URL friendly:</p>
  
  <pre><code>function toAscii($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;
  }
  </code></pre>
  
  <p>and my search engine uses http location like this:</p>
  
  <pre><code>if ($q != '') {
     header( 'Location: http://'.$_SERVER['SERVER_NAME'].'/news/'.toAscii($q).'.html' );
     die();
  }
  else
  {
      header('Location:http://'.$_SERVER['SERVER_NAME'].'/news/');
      die();
  }
  </code></pre>
  
  <p>Thanks</p>