回答編集履歴
5
追記
answer
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
preg_match_all('/<a.*target="_blank".*<\/a>/i', $the_content, $matches);
|
12
12
|
foreach ($matches as $match){
|
13
13
|
foreach ($match as $m){
|
14
|
-
$the_content= str_replace($m, '<div>'.$m.'</div>', $the_content);
|
14
|
+
$the_content= str_replace($m, '<div id="hoge">'.$m.'</div>', $the_content);
|
15
15
|
}
|
16
16
|
}
|
17
17
|
```
|
4
修正
answer
CHANGED
@@ -2,4 +2,17 @@
|
|
2
2
|
```PHP
|
3
3
|
$the_content = preg_replace('/^<a[\s\S]*target="_blank"[\s\S]*<\/a>$/i', '<div id="hoge">$1</div>', $the_content);
|
4
4
|
```
|
5
|
-
正規表現には正直自信はありませんが、一応[正規表現チェッカー](http://okumocchi.jp/php/re.php)ではマッチしました。
|
5
|
+
正規表現には正直自信はありませんが、一応[正規表現チェッカー](http://okumocchi.jp/php/re.php)ではマッチしました。
|
6
|
+
|
7
|
+
修正コード
|
8
|
+
---
|
9
|
+
上記コードでは全くダメだったので修正
|
10
|
+
```PHP
|
11
|
+
preg_match_all('/<a.*target="_blank".*<\/a>/i', $the_content, $matches);
|
12
|
+
foreach ($matches as $match){
|
13
|
+
foreach ($match as $m){
|
14
|
+
$the_content= str_replace($m, '<div>'.$m.'</div>', $the_content);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
```
|
18
|
+
これでもまだ問題はありますが、一応置換はできるかと思います。
|
3
修正
answer
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
```PHP
|
3
3
|
$the_content = preg_replace('/^<a[\s\S]*target="_blank"[\s\S]*<\/a>$/i', '<div id="hoge">$1</div>', $the_content);
|
4
4
|
```
|
5
|
-
正規表現には正直自
|
5
|
+
正規表現には正直自信はありませんが、一応[正規表現チェッカー](http://okumocchi.jp/php/re.php)ではマッチしました。
|
2
コードミスを修正
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
次のようにしてみるといかがでしょうか?
|
2
2
|
```PHP
|
3
|
-
$the_content = preg_replace('/^<a[\s\S]*target="_blank"[\s\S]*<\/a>$/', '<div id="hoge">$1</div>', $the_content);
|
3
|
+
$the_content = preg_replace('/^<a[\s\S]*target="_blank"[\s\S]*<\/a>$/i', '<div id="hoge">$1</div>', $the_content);
|
4
4
|
```
|
5
5
|
正規表現には正直自身はありませんが、一応[正規表現チェッカー](http://okumocchi.jp/php/re.php)ではマッチしました。
|
1
コードミスを修正
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
次のようにしてみるといかがでしょうか?
|
2
2
|
```PHP
|
3
|
-
$the_content = preg_replace('/^<a[\s\S]*target="_blank"[\s\S]*\/>$/', '<div id="hoge">$1</div>', $the_content);
|
3
|
+
$the_content = preg_replace('/^<a[\s\S]*target="_blank"[\s\S]*<\/a>$/', '<div id="hoge">$1</div>', $the_content);
|
4
4
|
```
|
5
5
|
正規表現には正直自身はありませんが、一応[正規表現チェッカー](http://okumocchi.jp/php/re.php)ではマッチしました。
|