次の関数は、いくつかの単語を配列に取り除き、空白を調整し、必要なものを実行します。私もダッシュを削除する必要があります。私はダッシュを単語としても書いています。しかし、この関数はダッシュを削除しません。どうしましたか?文字列からダッシュ( - )を取り除くことができません
function stripwords($string)
{
// build pattern once
static $pattern = null;
if ($pattern === null) {
// pull words to remove from somewhere
$words = array('alpha', 'beta', '-');
// escape special characters
foreach ($words as &$word) {
$word = preg_quote($word, '#');
}
// combine to regex
$pattern = '#\b(' . join('|', $words) . ')\b\s*#iS';
}
$print = preg_replace($pattern, '', $string);
list($firstpart)=explode('+', $print);
return $firstpart;
}
'$ pattern'はどのように見えますか? –
これはハイフンで、ダッシュではありません。ダッシュは: - – Buddy
期待どおりに動作しない例がありますか? – Gumbo