에서 다음 함수는 배열에 일부 단어를 제거합니다 공백을 조정하고 내가 필요한 다른 작업을 수행. 나는 또한 단어로 쓰는 것처럼 대시를 제거해야합니다. 그러나이 함수는 대시를 제거하지 않습니다. 뭐가 문제 야?대시를 제거 할 수 없습니다 (-) 문자열
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;
}
'$ 패턴 '은 어떻게 생겼습니까? –
대시가 아닌 하이픈입니다. 대시가 : - – Buddy
예상대로 작동하지 않는 예제를 줄 수 있습니까? – Gumbo