【发布时间】:2014-04-02 13:38:21
【问题描述】:
我想查看一个字符串,看看字符串中的任何单词是否与文本文件中的单词匹配。
假设我有一个 product.txt 文件,它包含:
苹果 索尼 戴森 麦当劳 iPod
这是我的代码:
<?php
$productFile = file_get_contents('products.txt', FILE_USE_INCLUDE_PATH);
/*
* product.txt file contains
* apple
* pc
* ipod
* mcdonalds
*/
$status = 'i love watching tv on my brand new apple mac';
if (strpos($status,$productFile) !== false) {
echo 'the status contains a product';
}
else{
echo 'The status doesnt contain a product';
}
?>
现在它告诉我状态不包含它所包含的产品,任何人都可以看到我哪里出错了吗?
【问题讨论】:
标签: php text-files