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

回答編集履歴

2

a

2016/04/07 21:49

投稿

mpyw
mpyw

スコア5223

answer CHANGED
@@ -9,8 +9,9 @@
9
9
  - [strpos](http://php.net/manual/ja/function.strpos.php)
10
10
 
11
11
  ```php
12
+ $haystack = file_get_contents('haystack.txt');
12
13
  $needle = 'http://example.com/example.html';
13
- if (strpos(file_get_contents('haystack.txt'), $needle) !== false) {
14
+ if (strpos($haystack, $needle) !== false) {
14
15
  echo '見つかりました';
15
16
  } else {
16
17
  echo '見つかりませんでした';

1

a

2016/04/07 21:49

投稿

mpyw
mpyw

スコア5223

answer CHANGED
@@ -6,4 +6,13 @@
6
6
 
7
7
  また,特定のURLが文字列中に存在するか調べるだけであればそもそも正規表現を使う必要がありません.`strpos`関数で十分です.
8
8
 
9
- - [strpos](http://php.net/manual/ja/function.strpos.php)
9
+ - [strpos](http://php.net/manual/ja/function.strpos.php)
10
+
11
+ ```php
12
+ $needle = 'http://example.com/example.html';
13
+ if (strpos(file_get_contents('haystack.txt'), $needle) !== false) {
14
+ echo '見つかりました';
15
+ } else {
16
+ echo '見つかりませんでした';
17
+ }
18
+ ```