質問編集履歴
7
7
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,11 +10,11 @@
|
|
10
10
|
|
11
11
|
```html
|
12
12
|
|
13
|
-
http://exmple.com/id=http://exmple.com/abc/a123/
|
13
|
+
<a href="http://exmple.com/id=http://exmple.com/abc/a123/">
|
14
14
|
|
15
|
-
http://exmple.com/id=http://exmple.com/abc/b456/
|
15
|
+
<a href="http://exmple.com/id=http://exmple.com/abc/b456/">
|
16
16
|
|
17
|
-
http://exmple.com/id=http://exmple.com/abc/c789/
|
17
|
+
<a href="http://exmple.com/id=http://exmple.com/abc/c789/">
|
18
18
|
|
19
19
|
|
20
20
|
|
@@ -30,11 +30,11 @@
|
|
30
30
|
|
31
31
|
```ここに言語を入力
|
32
32
|
|
33
|
-
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
|
33
|
+
<a href="http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A/">
|
34
34
|
|
35
|
-
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
|
35
|
+
<a href="http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A/">
|
36
36
|
|
37
|
-
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
|
37
|
+
<a href="http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A/">
|
38
38
|
|
39
39
|
```
|
40
40
|
|
6
6
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,6 +40,28 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
+
自分で考えたものはこんな感じのイメージでした。
|
44
|
+
|
45
|
+
```php
|
46
|
+
|
47
|
+
$html = file_get_contents('file.html');
|
48
|
+
|
49
|
+
$string = $html;
|
50
|
+
|
51
|
+
$pattern = ""; //置換対象検索文字列(正規表現 id=以降部分)
|
52
|
+
|
53
|
+
$eurl = (urlencode("$pattern")); //$patternでurlencode
|
54
|
+
|
55
|
+
$replacement = "$eurl"; //$patternを$eurlに置換
|
56
|
+
|
57
|
+
echo preg_replace($pattern,$replace,$string);//出力
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
43
65
|
どななたわかる方、教えてください。
|
44
66
|
|
45
67
|
よろしくお願い致します。
|
5
5
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,118 +1,6 @@
|
|
1
1
|
a.html内のid=以降を全てurlエンコードしたいです。
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
a.html
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
```html
|
12
|
-
|
13
|
-
http://exmple.com/id=http://exmple.com/abc/以降ランダムです/
|
14
|
-
|
15
|
-
http://exmple.com/id=http://exmple.com/abc/以降ランダムです/
|
16
|
-
|
17
|
-
http://exmple.com/id=http://exmple.com/abc/以降ランダムです/
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
・・・
|
22
|
-
|
23
|
-
```
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
sample.php
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
```php
|
32
|
-
|
33
|
-
$html = file_get_contents('a.html');
|
34
|
-
|
35
|
-
$string = "$html";
|
36
|
-
|
37
|
-
$pattern = "http:/exmple.com/以降ランダムです/";
|
38
|
-
|
39
|
-
$replacement = urlencode("$pattern");
|
40
|
-
|
41
|
-
echo ereg_replace($pattern, $replacement, $string);
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
この正規表現 http:/exmple.com/以降ランダムです/ が分かりません。
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
試した正規表現は
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
だめだった例
|
56
|
-
|
57
|
-
"|(http://exmple.com/)(.*$)|"
|
58
|
-
|
59
|
-
"http\:\/\/exmple\.com\/)(.*$)"
|
60
|
-
|
61
|
-
"http\:\/\/exmple\.com\/)$1"
|
62
|
-
|
63
|
-
・・・
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
以下これは全てのurlを対象としてurlencodeはできました。
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
```php
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
$html = file_get_contents('a.html');
|
76
|
-
|
77
|
-
$string = "$html";
|
78
|
-
|
79
|
-
$pattern = "https?://[\w/:%#\$&\?\(\)~\.=\+\-]+";
|
80
|
-
|
81
|
-
$replacement = urlencode("$pattern");
|
82
|
-
|
83
|
-
echo ereg_replace($pattern, $replacement, $string);
|
84
|
-
|
85
|
-
```
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
ですがhttp://exmple.com/が頭についたもの
|
94
|
-
|
95
|
-
がほしいと思っています。
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
http://exmple.com/id=http://exmple.com/abc/以降ランダム/ に対して
|
100
|
-
|
101
|
-
id=以降のurl部分全てをエンコードしたいです。
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
どななたわかる方、教えてください。
|
106
|
-
|
107
|
-
よろしくお願い致します。
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
追記
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
なにが何になれば納得がいくのかというと
|
116
4
|
|
117
5
|
|
118
6
|
|
@@ -138,6 +26,8 @@
|
|
138
26
|
|
139
27
|
再現するためにサイトで手動エンコードしました。
|
140
28
|
|
29
|
+
|
30
|
+
|
141
31
|
```ここに言語を入力
|
142
32
|
|
143
33
|
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
|
@@ -147,3 +37,9 @@
|
|
147
37
|
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
|
148
38
|
|
149
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
どななたわかる方、教えてください。
|
44
|
+
|
45
|
+
よろしくお願い致します。
|
4
補足4
test
CHANGED
File without changes
|
test
CHANGED
@@ -147,63 +147,3 @@
|
|
147
147
|
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
|
148
148
|
|
149
149
|
```
|
150
|
-
|
151
|
-
そのためのコードが必要で
|
152
|
-
|
153
|
-
今自分でわかっているものはこれです。
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
```php
|
158
|
-
|
159
|
-
$html = file_get_contents("a.html"); //ファイルを読み込む
|
160
|
-
|
161
|
-
$string = "$html"; //$stringに$htmlを代入
|
162
|
-
|
163
|
-
$pattern = '正規表現'; //これがid=以降を示す正規表現
|
164
|
-
|
165
|
-
$replacement = urlencode("$pattern"); //$patternでurlencodeしたものへ置換する。
|
166
|
-
|
167
|
-
echo preg_replace($pattern, $replacement, $string); //結果を標準出力する。
|
168
|
-
|
169
|
-
```
|
170
|
-
|
171
|
-
以下では
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
```php
|
176
|
-
|
177
|
-
$pattern = 'https?://[\w/:%#\$&\?\(\)~\.=\+\-]+';
|
178
|
-
|
179
|
-
```
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
正規表現の一部が置換後文字として扱われてしまい、リンク切れにもなってしまいました。
|
184
|
-
|
185
|
-
ここは置換後文字列になるので正規表現を書いたらそのまま置換されるのでしょうか。
|
186
|
-
|
187
|
-
urlencodeと$replacementを分けて書けばいいのかもしれないと
|
188
|
-
|
189
|
-
書いていて思いました。
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
id=以降を示す正規表現はどうかけばいいのか・・・
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
これもできない例ですが
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
```php
|
204
|
-
|
205
|
-
$pattern = http\:\/\/exmple\.com\/abc\/(.*$) // ???!
|
206
|
-
|
207
|
-
```
|
208
|
-
|
209
|
-
という微妙な感じになっております。
|
3
追記修正2
test
CHANGED
File without changes
|
test
CHANGED
@@ -147,3 +147,63 @@
|
|
147
147
|
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
|
148
148
|
|
149
149
|
```
|
150
|
+
|
151
|
+
そのためのコードが必要で
|
152
|
+
|
153
|
+
今自分でわかっているものはこれです。
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
```php
|
158
|
+
|
159
|
+
$html = file_get_contents("a.html"); //ファイルを読み込む
|
160
|
+
|
161
|
+
$string = "$html"; //$stringに$htmlを代入
|
162
|
+
|
163
|
+
$pattern = '正規表現'; //これがid=以降を示す正規表現
|
164
|
+
|
165
|
+
$replacement = urlencode("$pattern"); //$patternでurlencodeしたものへ置換する。
|
166
|
+
|
167
|
+
echo preg_replace($pattern, $replacement, $string); //結果を標準出力する。
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
以下では
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```php
|
176
|
+
|
177
|
+
$pattern = 'https?://[\w/:%#\$&\?\(\)~\.=\+\-]+';
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
正規表現の一部が置換後文字として扱われてしまい、リンク切れにもなってしまいました。
|
184
|
+
|
185
|
+
ここは置換後文字列になるので正規表現を書いたらそのまま置換されるのでしょうか。
|
186
|
+
|
187
|
+
urlencodeと$replacementを分けて書けばいいのかもしれないと
|
188
|
+
|
189
|
+
書いていて思いました。
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
id=以降を示す正規表現はどうかけばいいのか・・・
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
これもできない例ですが
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
```php
|
204
|
+
|
205
|
+
$pattern = http\:\/\/exmple\.com\/abc\/(.*$) // ???!
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
という微妙な感じになっております。
|
2
追記訂正1
test
CHANGED
File without changes
|
test
CHANGED
@@ -144,6 +144,6 @@
|
|
144
144
|
|
145
145
|
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
|
146
146
|
|
147
|
-
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F
|
147
|
+
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
|
148
148
|
|
149
149
|
```
|
1
追記です
test
CHANGED
File without changes
|
test
CHANGED
@@ -105,3 +105,45 @@
|
|
105
105
|
どななたわかる方、教えてください。
|
106
106
|
|
107
107
|
よろしくお願い致します。
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
追記
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
なにが何になれば納得がいくのかというと
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
これが
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
```html
|
124
|
+
|
125
|
+
http://exmple.com/id=http://exmple.com/abc/a123/
|
126
|
+
|
127
|
+
http://exmple.com/id=http://exmple.com/abc/b456/
|
128
|
+
|
129
|
+
http://exmple.com/id=http://exmple.com/abc/c789/
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
・・・
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
これになればいいという意味です。
|
138
|
+
|
139
|
+
再現するためにサイトで手動エンコードしました。
|
140
|
+
|
141
|
+
```ここに言語を入力
|
142
|
+
|
143
|
+
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
|
144
|
+
|
145
|
+
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
|
146
|
+
|
147
|
+
http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F
|
148
|
+
|
149
|
+
```
|