回答編集履歴
1
追記
    
        answer	
    CHANGED
    
    | @@ -14,4 +14,22 @@ | |
| 14 14 | 
             
            $string=preg_replace_callback($pattern,$replacement,$string);
         | 
| 15 15 | 
             
            print nl2br($string);
         | 
| 16 16 | 
             
            ?>
         | 
| 17 | 
            +
            ```
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            # 追記
         | 
| 20 | 
            +
            hrefの中の処理であればこんな感じで?
         | 
| 21 | 
            +
            ```PHP
         | 
| 22 | 
            +
            <?PHP
         | 
| 23 | 
            +
            $string=<<<eof
         | 
| 24 | 
            +
            test
         | 
| 25 | 
            +
            <a href="http://exmple.com/id=http://exmple.com/abc/a123/">
         | 
| 26 | 
            +
            <a href='http://exmple.com/id=http://exmple.com/abc/b456/'>
         | 
| 27 | 
            +
            <a href="http://exmple.com/id=http://exmple.com/abc/c789/">
         | 
| 28 | 
            +
            test
         | 
| 29 | 
            +
            eof;
         | 
| 30 | 
            +
            $pattern="|(href=([\"'])http://exmple.com/.+?=)(.+)(?=\\2)|m" ;
         | 
| 31 | 
            +
            $replacement=function($a){return $a[1].urlencode($a[3]);};
         | 
| 32 | 
            +
            $string=preg_replace_callback($pattern,$replacement,$string);
         | 
| 33 | 
            +
            print nl2br(htmlspecialchars($string));
         | 
| 34 | 
            +
             | 
| 17 35 | 
             
            ```
         | 
