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

回答編集履歴

3

修正

2016/07/15 13:49

投稿

退会済みユーザー
answer CHANGED
@@ -17,8 +17,9 @@
17
17
  http://exmple.com/id=http://exmple.com/abc/349094/
18
18
  STR;
19
19
 
20
- $res = [];
20
+ $res = array();
21
- foreach (explode(PHP_EOL, $string) as $line) {
21
+ $lines = explode(PHP_EOL, $string);
22
+ foreach ($lines as $line) {
22
23
  $url = parse_url($line);
23
24
  $path = $url['path'];
24
25
  $arr = explode('=', $path);

2

修正

2016/07/15 13:49

投稿

退会済みユーザー
answer CHANGED
@@ -6,3 +6,29 @@
6
6
  この関数は PHP 5.3.0 で 非推奨 となり、 PHP 7.0.0 で 削除 されました。
7
7
  この関数の代替として、これらが使えます。
8
8
  preg_replace()
9
+
10
+ ---
11
+
12
+ ```php
13
+
14
+ $string = <<<STR
15
+ http://exmple.com/id=http://exmple.com/abc/102912/
16
+ http://exmple.com/id=http://exmple.com/abc/327429/
17
+ http://exmple.com/id=http://exmple.com/abc/349094/
18
+ STR;
19
+
20
+ $res = [];
21
+ foreach (explode(PHP_EOL, $string) as $line) {
22
+ $url = parse_url($line);
23
+ $path = $url['path'];
24
+ $arr = explode('=', $path);
25
+
26
+ $res[] = sprintf('%s://%s%s=%s'
27
+ , $url['scheme']
28
+ , $url['host']
29
+ , $arr[0]
30
+ , urlencode($arr[1])
31
+ );
32
+ }
33
+ var_dump($res);
34
+ ```

1

追記

2016/07/15 12:38

投稿

退会済みユーザー
answer CHANGED
@@ -1,1 +1,8 @@
1
- [parse_url()](http://php.net/manual/ja/function.parse-url.php) を使ったほうが楽で間違いがないと思いますよ。
1
+ [parse_url()](http://php.net/manual/ja/function.parse-url.php) を使ったほうが楽で間違いがないと思いますよ。
2
+
3
+ [ereg_replace()](http://php.net/manual/ja/function.ereg-replace.php)
4
+
5
+ > 警告
6
+ この関数は PHP 5.3.0 で 非推奨 となり、 PHP 7.0.0 で 削除 されました。
7
+ この関数の代替として、これらが使えます。
8
+ preg_replace()