What are potential pitfalls to avoid when extracting keywords using PHP?

Potential pitfalls to avoid when extracting keywords using PHP include not properly handling special characters, not considering case sensitivity, and not accounting for stopwords. To address these issues, it is important to sanitize the input text, convert all characters to lowercase, and remove common stopwords from the extracted keywords.

$inputText = "This is a sample input text with some keywords.";
$inputText = strtolower($inputText);
$inputText = preg_replace('/[^a-zA-Z0-9\s]/', '', $inputText);

$stopwords = array('is', 'a', 'with', 'some');
$keywords = array_diff(explode(' ', $inputText), $stopwords);

print_r($keywords);