Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php从数组中查找字符串中出现的所有单词_Php_Arrays_String_File - Fatal编程技术网

使用php从数组中查找字符串中出现的所有单词

使用php从数组中查找字符串中出现的所有单词,php,arrays,string,file,Php,Arrays,String,File,$input='myntralove.com' 我有一个数组 $array=array('my','myntra','love','myntralove'); 我的预期产出是: 我的 明特拉 爱 网站 你能从test.txt文件中发布一个示例行吗?你能从test.txt文件中发布一个示例行吗? <?php $mystring = 'cheapestbricks.com.au'; $findmes = ['cheapest','bricks']; $array = explode("\

$input='myntralove.com' 我有一个数组 $array=array('my','myntra','love','myntralove'); 我的预期产出是: 我的 明特拉 爱 网站


你能从
test.txt
文件中发布一个示例行吗?你能从
test.txt
文件中发布一个示例行吗?
<?php
$mystring = 'cheapestbricks.com.au';
$findmes   = ['cheapest','bricks'];

$array = explode("\n", file_get_contents('test.txt'));


foreach($array as $findme) {

    $pos = strpos($mystring, trim($findme));
    if ($pos === false) {
        //echo "The string '$findme' was not found in the string '$mystring'";
    } else {
        echo $findme.'<br/>';
    }
}