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