回答編集履歴

1

追記

2016/07/21 04:30

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1,3 +1,43 @@
1
1
  すべての文字列からurlに合致した部分をpreg_replaceで’’に変換してしまえば
2
2
 
3
3
  残りがurl以外の文字列です
4
+
5
+
6
+
7
+ # 追記
8
+
9
+ 具体的にはこう
10
+
11
+ ```PHP
12
+
13
+ <?PHP
14
+
15
+ $str=<<<eof
16
+
17
+ test
18
+
19
+ 1:testhttp://example.com test
20
+
21
+ 2:testhttp://example.com?a=1&b=2#hogehoge test
22
+
23
+ 3:testhttp://example.com testhttp://example.com test
24
+
25
+ 4:test
26
+
27
+ eof;
28
+
29
+ $pattern='/https?:\/\/[a-zA-Z0-9\-\.\/\?\@&=:~#]+/';
30
+
31
+ $replacement="";
32
+
33
+ $array=preg_split($pattern,$str);//配列に抽出する場合
34
+
35
+ var_dump($array);
36
+
37
+ $newstr=preg_replace($pattern,$replacement,$str);//全部をつなげて表示する場合
38
+
39
+ print nl2br($newstr);
40
+
41
+ ?>
42
+
43
+ ```