質問編集履歴
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,14 +29,14 @@
|
|
29
29
|
テスト<a href="https://example.com">https://example.com</a>テスト
|
30
30
|
|
31
31
|
#OK
|
32
|
-
<a href="https://example.com">コンテンツ</a>
|
32
|
+
テスト<a href="https://example.com">コンテンツ</a>テスト
|
33
33
|
↓
|
34
|
-
<a href="https://example.com">コンテンツ</a>
|
34
|
+
テスト<a href="https://example.com">コンテンツ</a>テスト
|
35
35
|
|
36
36
|
#NG
|
37
|
-
<a href="https://example.com">https://example.com</a>
|
37
|
+
テスト<a href="https://example.com">https://example.com</a>テスト
|
38
38
|
↓
|
39
|
-
<a href="https://example.com"><a href="https://example.com">https://example.com</a></a>
|
39
|
+
テスト<a href="https://example.com"><a href="https://example.com">https://example.com</a></a>テスト
|
40
40
|
|
41
41
|
|
42
42
|
```
|
1
例追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,9 +7,6 @@
|
|
7
7
|
[こちら](https://qiita.com/sukobuto/items/b6cdfa966b29823c62f0)を参考にしました。
|
8
8
|
|
9
9
|
```php
|
10
|
-
|
11
|
-
echo url2link('<a href="https://example.com">https://example.com</a>');
|
12
|
-
|
13
10
|
function url2link($body, $link_title = null)
|
14
11
|
{
|
15
12
|
$pattern = '/(?<!href=")https?://[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+/';
|
@@ -25,10 +22,16 @@
|
|
25
22
|
|
26
23
|
下記のように、コンテンツ部分にURLが含まれる場合はコンテンツ部分もaタグに置換されてしまいます。
|
27
24
|
```html
|
25
|
+
|
28
26
|
#OK
|
27
|
+
テストhttps://example.comテスト
|
28
|
+
↓
|
29
|
+
テスト<a href="https://example.com">https://example.com</a>テスト
|
30
|
+
|
31
|
+
#OK
|
29
32
|
<a href="https://example.com">コンテンツ</a>
|
30
33
|
↓
|
31
|
-
|
34
|
+
<a href="https://example.com">コンテンツ</a>
|
32
35
|
|
33
36
|
#NG
|
34
37
|
<a href="https://example.com">https://example.com</a>
|