title: How to delete all chars from end to first space of PHP variable?
body: <p>I would like to delete one last word of String variable in PHP. I tried to do it according to this code: <a href="https://stackoverflow.com/a/29428662/10490051">https://stackoverflow.com/a/29428662/10490051</a>. But it doesn't solve my problem.</p>
  <p>I would like to use it for SQL argument:</p>
  <pre><code>$sql_request = &quot;SELECT fullname FROM names WHERE lastname='johnson' and city='oxford' &quot;;
  
  
  $sql_request = preg_replace('/\W\w+\s*(\W*)$/', '$1', $sql_request);
  
  echo $sql_request;     
  </code></pre>
  <p>Specifically I need to delete whole last argument: <strong>city='oxford'</strong>.
  (I need to delete all from end to first space)
  But result of my code will be:</p>
  <pre><code>SELECT fullname FROM names WHERE lastname='johnson' and city='
  </code></pre>
  <p>but I need this:</p>
  <pre><code>SELECT fullname FROM names WHERE lastname='johnson' and
  </code></pre>
  <p>So how to delete whole last argument and not only part of them?
  Thank you.</p>