質問編集履歴

2

整理

2022/11/29 09:45

投稿

maibear3
maibear3

スコア5

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,6 @@
1
+ ```ここに言語を入力
2
+ コード
1
- ### 使用するファイル
3
+ ```### 使用するファイル
2
4
  test1.csv↓
3
5
  name
4
6
  りんご
@@ -26,7 +28,8 @@
26
28
  みかん,150
27
29
 
28
30
  ### 試したこと
29
-
31
+ php
32
+ コード
30
33
  <?php
31
34
  $search_word = 'りんご';
32
35
  if (($handle = fopen("test2.csv", "r")) !== FALSE) {

1

試したこと追記

2022/11/29 09:37

投稿

maibear3
maibear3

スコア5

test CHANGED
File without changes
test CHANGED
@@ -25,5 +25,18 @@
25
25
  みかん,300
26
26
  みかん,150
27
27
 
28
+ ### 試したこと
29
+
30
+ <?php
31
+ $search_word = 'りんご';
32
+ if (($handle = fopen("test2.csv", "r")) !== FALSE) {
33
+ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
34
+ if(count(preg_grep('/'.$search_word.'/', $data)) > 0){
35
+ var_dump($data);
36
+ }
37
+ }
38
+ fclose($handle);
39
+ }
40
+ で行った結果あいまい検索になってしまい、またヒットした果物の価格まで表示できませんでした。
28
41
 
29
42