質問するログイン新規登録

質問編集履歴

7

7

2016/07/15 23:21

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -4,9 +4,9 @@
4
4
  これが
5
5
 
6
6
  ```html
7
- http://exmple.com/id=http://exmple.com/abc/a123/
7
+ <a href="http://exmple.com/id=http://exmple.com/abc/a123/">
8
- http://exmple.com/id=http://exmple.com/abc/b456/
8
+ <a href="http://exmple.com/id=http://exmple.com/abc/b456/">
9
- http://exmple.com/id=http://exmple.com/abc/c789/
9
+ <a href="http://exmple.com/id=http://exmple.com/abc/c789/">
10
10
 
11
11
  ・・・
12
12
  ```
@@ -14,9 +14,9 @@
14
14
  再現するためにサイトで手動エンコードしました。
15
15
 
16
16
  ```ここに言語を入力
17
- http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
17
+ <a href="http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A/">
18
- http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
18
+ <a href="http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A/">
19
- http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
19
+ <a href="http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A/">
20
20
  ```
21
21
 
22
22
  自分で考えたものはこんな感じのイメージでした。

6

2016/07/15 23:21

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -19,5 +19,16 @@
19
19
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
20
20
  ```
21
21
 
22
+ 自分で考えたものはこんな感じのイメージでした。
23
+ ```php
24
+ $html = file_get_contents('file.html');
25
+ $string = $html;
26
+ $pattern = ""; //置換対象検索文字列(正規表現 id=以降部分)
27
+ $eurl = (urlencode("$pattern")); //$patternでurlencode
28
+ $replacement = "$eurl"; //$patternを$eurlに置換
29
+ echo preg_replace($pattern,$replace,$string);//出力
30
+
31
+ ```
32
+
22
33
  どななたわかる方、教えてください。
23
34
  よろしくお願い致します。

5

5

2016/07/15 22:59

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -1,62 +1,6 @@
1
1
  a.html内のid=以降を全てurlエンコードしたいです。
2
2
 
3
3
 
4
- a.html
5
-
6
- ```html
7
- http://exmple.com/id=http://exmple.com/abc/以降ランダムです/
8
- http://exmple.com/id=http://exmple.com/abc/以降ランダムです/
9
- http://exmple.com/id=http://exmple.com/abc/以降ランダムです/
10
-
11
- ・・・
12
- ```
13
-
14
- sample.php
15
-
16
- ```php
17
- $html = file_get_contents('a.html');
18
- $string = "$html";
19
- $pattern = "http:/exmple.com/以降ランダムです/";
20
- $replacement = urlencode("$pattern");
21
- echo ereg_replace($pattern, $replacement, $string);
22
-
23
- ```
24
- この正規表現 http:/exmple.com/以降ランダムです/ が分かりません。
25
-
26
- 試した正規表現は
27
-
28
- だめだった例
29
- "|(http://exmple.com/)(.*$)|"
30
- "http\:\/\/exmple\.com\/)(.*$)"
31
- "http\:\/\/exmple\.com\/)$1"
32
- ・・・
33
-
34
- 以下これは全てのurlを対象としてurlencodeはできました。
35
-
36
- ```php
37
-
38
- $html = file_get_contents('a.html');
39
- $string = "$html";
40
- $pattern = "https?://[\w/:%#\$&\?\(\)~\.=\+\-]+";
41
- $replacement = urlencode("$pattern");
42
- echo ereg_replace($pattern, $replacement, $string);
43
- ```
44
-
45
-
46
-
47
- ですがhttp://exmple.com/が頭についたもの
48
- がほしいと思っています。
49
-
50
- http://exmple.com/id=http://exmple.com/abc/以降ランダム/ に対して
51
- id=以降のurl部分全てをエンコードしたいです。
52
-
53
- どななたわかる方、教えてください。
54
- よろしくお願い致します。
55
-
56
- 追記
57
-
58
- なにが何になれば納得がいくのかというと
59
-
60
4
  これが
61
5
 
62
6
  ```html
@@ -68,8 +12,12 @@
68
12
  ```
69
13
  これになればいいという意味です。
70
14
  再現するためにサイトで手動エンコードしました。
15
+
71
16
  ```ここに言語を入力
72
17
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
73
18
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
74
19
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
75
- ```
20
+ ```
21
+
22
+ どななたわかる方、教えてください。
23
+ よろしくお願い致します。

4

補足4

2016/07/15 22:43

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -72,34 +72,4 @@
72
72
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
73
73
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
74
74
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
75
- ```
75
+ ```
76
- そのためのコードが必要で
77
- 今自分でわかっているものはこれです。
78
-
79
- ```php
80
- $html = file_get_contents("a.html"); //ファイルを読み込む
81
- $string = "$html"; //$stringに$htmlを代入
82
- $pattern = '正規表現'; //これがid=以降を示す正規表現
83
- $replacement = urlencode("$pattern"); //$patternでurlencodeしたものへ置換する。
84
- echo preg_replace($pattern, $replacement, $string); //結果を標準出力する。
85
- ```
86
- 以下では
87
-
88
- ```php
89
- $pattern = 'https?://[\w/:%#\$&\?\(\)~\.=\+\-]+';
90
- ```
91
-
92
- 正規表現の一部が置換後文字として扱われてしまい、リンク切れにもなってしまいました。
93
- ここは置換後文字列になるので正規表現を書いたらそのまま置換されるのでしょうか。
94
- urlencodeと$replacementを分けて書けばいいのかもしれないと
95
- 書いていて思いました。
96
-
97
- id=以降を示す正規表現はどうかけばいいのか・・・
98
-
99
-
100
- これもできない例ですが
101
-
102
- ```php
103
- $pattern = http\:\/\/exmple\.com\/abc\/(.*$) // ???!
104
- ```
105
- という微妙な感じになっております。

3

追記修正2

2016/07/15 21:16

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -72,4 +72,34 @@
72
72
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
73
73
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
74
74
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
75
- ```
75
+ ```
76
+ そのためのコードが必要で
77
+ 今自分でわかっているものはこれです。
78
+
79
+ ```php
80
+ $html = file_get_contents("a.html"); //ファイルを読み込む
81
+ $string = "$html"; //$stringに$htmlを代入
82
+ $pattern = '正規表現'; //これがid=以降を示す正規表現
83
+ $replacement = urlencode("$pattern"); //$patternでurlencodeしたものへ置換する。
84
+ echo preg_replace($pattern, $replacement, $string); //結果を標準出力する。
85
+ ```
86
+ 以下では
87
+
88
+ ```php
89
+ $pattern = 'https?://[\w/:%#\$&\?\(\)~\.=\+\-]+';
90
+ ```
91
+
92
+ 正規表現の一部が置換後文字として扱われてしまい、リンク切れにもなってしまいました。
93
+ ここは置換後文字列になるので正規表現を書いたらそのまま置換されるのでしょうか。
94
+ urlencodeと$replacementを分けて書けばいいのかもしれないと
95
+ 書いていて思いました。
96
+
97
+ id=以降を示す正規表現はどうかけばいいのか・・・
98
+
99
+
100
+ これもできない例ですが
101
+
102
+ ```php
103
+ $pattern = http\:\/\/exmple\.com\/abc\/(.*$) // ???!
104
+ ```
105
+ という微妙な感じになっております。

2

追記訂正1

2016/07/15 20:41

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -71,5 +71,5 @@
71
71
  ```ここに言語を入力
72
72
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
73
73
  http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
74
- http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F
74
+ http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F%0D%0A
75
75
  ```

1

追記です

2016/07/15 19:19

投稿

seel
seel

スコア25

title CHANGED
File without changes
body CHANGED
@@ -51,4 +51,25 @@
51
51
  id=以降のurl部分全てをエンコードしたいです。
52
52
 
53
53
  どななたわかる方、教えてください。
54
- よろしくお願い致します。
54
+ よろしくお願い致します。
55
+
56
+ 追記
57
+
58
+ なにが何になれば納得がいくのかというと
59
+
60
+ これが
61
+
62
+ ```html
63
+ http://exmple.com/id=http://exmple.com/abc/a123/
64
+ http://exmple.com/id=http://exmple.com/abc/b456/
65
+ http://exmple.com/id=http://exmple.com/abc/c789/
66
+
67
+ ・・・
68
+ ```
69
+ これになればいいという意味です。
70
+ 再現するためにサイトで手動エンコードしました。
71
+ ```ここに言語を入力
72
+ http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fa123%2F%0D%0A
73
+ http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fb456%2F%0D%0A
74
+ http://exmple.com/id=http%3A%2F%2Fexmple.com%2Fabc%2Fc789%2F
75
+ ```