在文本中搜索,并通过php选择关键字 [英] search in text , and select keywords by php

查看:31
本文介绍了在文本中搜索,并通过php选择关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好吗?

我有一个文本:

拜占庭人在 7 世纪早期短暂的波斯入侵后重新控制了这个国家,直到 639-42 年,当时埃及被穆斯林阿拉伯人入侵并被伊斯兰帝国征服.当他们在埃及击败拜占庭军队时,阿拉伯人将逊尼派伊斯兰教带到了该国.在这个时期的早期,埃及人开始将他们的新信仰与本土信仰和习俗融合在一起,导致各种苏菲教派蓬勃发展至今. [24]这些早期的仪式在科普特基督教时期幸存下来

The Byzantines were able to regain control of the country after a brief Persian invasion early in the 7th century, until 639-42, when Egypt was invaded and conquered by the Islamic Empire by the Muslim Arabs. When they defeated the Byzantine Armies in Egypt, the Arabs brought Sunni Islam to the country. Early in this period, Egyptians began to blend their new faith with indigenous beliefs and practices, leading to various Sufi orders that have flourished to this day.[24] These earlier rites had survived the period of Coptic Christianity

我想在此文本中搜索,并选择类别、标签

I want to search in this text , and select the categories , tags

<?php // this is some tags in Array , but I don't know which tag is used in this text.
$search_words = array("Egypt , Persian , Islamic , USA , Japan , Spain , Saudi Arabia");

foreach($search_words as $value){
        stristr($longText, $search_words); // I know this is mistake
    }?>

我想选择在这个简单中使用的词($search_words).

I want to select which words($search_words) used in this easy.

我为我的语言感到抱歉

推荐答案

$words_found = array();
foreach ($search_words as $word) {
    if (stristr($longText, $word)) {
         $words_found[] = $word;
    }
}

$words_found 现在是一个包含 $search_words 数组中所有出现在文本中的标签的数组.

$words_found is now an array containing all of the tags in the $search_words array which are present in the text.

另外,你的例子中数组的语法不正确,应该是这样的:

Also, the syntax of your the array in your example is incorrect, it should be this:

$search_words = array("Egypt", "Persian", "Islamic", "USA", "Japan", "Spain", "Saudi Arabia");

这篇关于在文本中搜索,并通过php选择关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆