這就是你想更換em dash。但是,你正在尋找一個常規的短跑。先嚐試運行通過這個爛攤子的串碼和閱讀blog article我是從
編輯
一個完整的工作示例,基本上粘貼在博客文章示例代碼和固定的一個小錯誤與你substr
function scrub_bogus_chars(&$text) {
// First, replace UTF-8 characters.
$text = str_replace(
array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);
// Next, replace their Windows-1252 equivalents.
$text = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
array("'", "'", '"', '"', '-', '--', '...'),
$text);
}
// Original string (with em dash)
$text = "this comes before – this comes after";
// Ensure regular dashes will be available
scrub_bogus_chars($text);
// Lastly, extract the interesting part of the original string
$char = ' - ';
$strpos = strpos($text, $char);
$text = substr($text, $strpos + strlen($char));
echo $text . PHP_EOL;
+1:對於實際閱讀這個問題(雖然,你的代碼看起來像ars ..我想這不能幫助)'= /' –
@note這適用於常規破折號和電子短劃線。 – quickshiftin
@tereško代碼大部分是剪切和粘貼的,但我只是把它清理乾淨了;) – quickshiftin