在文本中搜索,并通过php选择关键字

编程入门 行业动态 更新时间:2024-10-27 22:30:57
本文介绍了在文本中搜索,并通过php选择关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

你好吗?

我有一个文本:

拜占庭人在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 10:31:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关键字   文本中   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!