问问题
96 次
1 回答
1
一种通用的方法是使用自定义回调。如果您想采用 fix-broken-links 方式,请尝试以下操作:
$string = '"a dumb-ass car":http://example.com/funny-stuff-is-funny - funny-enough?';
echo preg_replace_callback( /* Fixing broken links with NON-BREAKING HYPHEN */
'@https?\://[^\s]+‑[^\s]+@u',
function ($matches) {
return str_replace('‑', '$1===-===', $matches[0]);
// or better, use strtr() for one-character replacement:
// return strtr($matches[0], '‑', '-');
},
preg_replace( /* NON-BREAKING HYPHEN inside of a word */
'@(?<= \w)-(?= \w)@xu',
'‑',
$string));
于 2012-10-14T16:17:20.667 回答