回答編集履歴

1

追記

2016/07/19 01:12

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -31,3 +31,39 @@
31
31
  ?>
32
32
 
33
33
  ```
34
+
35
+
36
+
37
+ # 追記
38
+
39
+ hrefの中の処理であればこんな感じで?
40
+
41
+ ```PHP
42
+
43
+ <?PHP
44
+
45
+ $string=<<<eof
46
+
47
+ test
48
+
49
+ <a href="http://exmple.com/id=http://exmple.com/abc/a123/">
50
+
51
+ <a href='http://exmple.com/id=http://exmple.com/abc/b456/'>
52
+
53
+ <a href="http://exmple.com/id=http://exmple.com/abc/c789/">
54
+
55
+ test
56
+
57
+ eof;
58
+
59
+ $pattern="|(href=([\"'])http://exmple.com/.+?=)(.+)(?=\\2)|m" ;
60
+
61
+ $replacement=function($a){return $a[1].urlencode($a[3]);};
62
+
63
+ $string=preg_replace_callback($pattern,$replacement,$string);
64
+
65
+ print nl2br(htmlspecialchars($string));
66
+
67
+
68
+
69
+ ```