title: Replace quotes with &quot; and substr function for words
body: <p>I am trying to replace double quotations with the word &quot; before inserting into the database, but when trying to fetch my text from the database I cannot convert the quotes after using this function to display certain words from the whole sentence.</p>
  
  <p>What I eventually want to do:</p>
  
  <ol>
  <li>Input the string <code>Word "blabla" more text</code> for example to the database </li>
  <li>Before putting to the database, convert the special characters like <code>"</code> to the correct code (<code>&amp;quote;</code>) </li>
  <li>When retrieving the string from the database, it must put the code <code>&amp;quote;</code> again to <code>"</code> to display on my page</li>
  </ol>
  
  <p>Besides that, I also want to create a function that works like <code>substr()</code> but splits on full words instead of single characters.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>function sanitize_words($string) {
      preg_match_all("/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]*/u",$string,$matches,PREG_PATTERN_ORDER);
      return $matches[0];
  }
  function words($text,$len) {
      $words_in_text = sanitize_words($text);
      $words_to_return = $len;
      $result = array_slice($words_in_text,0,$words_to_return);
      return implode(" ",$result);
  }
  </code></pre>
  
  <p>However when I try to replace the <code>"quot;"</code> text back to normal <code>"</code> quotes, it doesn't show on my page.</p>