title: Escape string for use in MySQL fulltext search
body: <p>I am using Laravel 4 and have set up the following query:</p>
  
  <pre><code>if(Input::get('keyword')) {
      $keyword = Input::get('keyword');
      $search = DB::connection()-&gt;getPdo()-&gt;quote($keyword);
      $query-&gt;whereRaw("MATCH(resources.name, resources.description, resources.website, resources.additional_info) AGAINST(? IN BOOLEAN MODE)", 
          array($search)
      );
  }
  </code></pre>
  
  <p>This query runs fine under normal use, however, if the user enters a string such as <code>++</code>, an error is thrown. Looking at the <a href="http://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html" rel="noreferrer">MySQl docs</a>, there are some keywords, such as <code>+</code> and <code>-</code> which have specific purposes. Is there a function which will escape these types of special characters from a string so it can be used in a fulltext search like above without throwing any errors?</p>
  
  <p>Here is an example of an error which is thrown:</p>
  
  <pre><code>{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42000]: Syntax error or access violation: 1064 syntax error, unexpected '+' (SQL: select * from `resources` where `duplicate` = 0 and MATCH(resources.name, resources.description, resources.website, resources.additional_info) AGAINST('c++' IN BOOLEAN MODE))","file":"\/var\/www\/html\/[...]\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connection.php","line":555}}
  </code></pre>
  
  <p>Solutions I've tried:</p>
  
  <pre><code>$search = str_ireplace(['+', '-'], ' ', $keyword);
  
  $search = filter_var($keyword, FILTER_SANITIZE_STRING);
  
  $search = DB::connection()-&gt;getPdo()-&gt;quote($keyword);
  </code></pre>
  
  <p>I'm assuming I will need to use regex. What's the best approach here?</p>