1
4

1 に答える 1

1

A general approach is to use a custom callback. Try the following, if you want to take the fix-broken-links way:

    $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 に答える