回答編集履歴
3
修正
test
CHANGED
@@ -36,9 +36,11 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
$res =
|
39
|
+
$res = array();
|
40
40
|
|
41
|
-
|
41
|
+
$lines = explode(PHP_EOL, $string);
|
42
|
+
|
43
|
+
foreach ($lines as $line) {
|
42
44
|
|
43
45
|
$url = parse_url($line);
|
44
46
|
|
2
修正
test
CHANGED
@@ -15,3 +15,53 @@
|
|
15
15
|
preg_replace()
|
16
16
|
|
17
17
|
|
18
|
+
|
19
|
+
---
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```php
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
$string = <<<STR
|
28
|
+
|
29
|
+
http://exmple.com/id=http://exmple.com/abc/102912/
|
30
|
+
|
31
|
+
http://exmple.com/id=http://exmple.com/abc/327429/
|
32
|
+
|
33
|
+
http://exmple.com/id=http://exmple.com/abc/349094/
|
34
|
+
|
35
|
+
STR;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
$res = [];
|
40
|
+
|
41
|
+
foreach (explode(PHP_EOL, $string) as $line) {
|
42
|
+
|
43
|
+
$url = parse_url($line);
|
44
|
+
|
45
|
+
$path = $url['path'];
|
46
|
+
|
47
|
+
$arr = explode('=', $path);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
$res[] = sprintf('%s://%s%s=%s'
|
52
|
+
|
53
|
+
, $url['scheme']
|
54
|
+
|
55
|
+
, $url['host']
|
56
|
+
|
57
|
+
, $arr[0]
|
58
|
+
|
59
|
+
, urlencode($arr[1])
|
60
|
+
|
61
|
+
);
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
var_dump($res);
|
66
|
+
|
67
|
+
```
|
1
追記
test
CHANGED
@@ -1 +1,17 @@
|
|
1
1
|
[parse_url()](http://php.net/manual/ja/function.parse-url.php) を使ったほうが楽で間違いがないと思いますよ。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
[ereg_replace()](http://php.net/manual/ja/function.ereg-replace.php)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
> 警告
|
10
|
+
|
11
|
+
この関数は PHP 5.3.0 で 非推奨 となり、 PHP 7.0.0 で 削除 されました。
|
12
|
+
|
13
|
+
この関数の代替として、これらが使えます。
|
14
|
+
|
15
|
+
preg_replace()
|
16
|
+
|
17
|
+
|