search
HomeBackend DevelopmentPHP Tutorial拆分、婚配关键字

拆分、匹配关键字
如何在一篇文章内拆分和匹配关键字?例如以下文章:

姐弟恋真的没好结果吗?我老公比我小五岁,我们刚结婚那会几乎天天吵,本来感情基础就没打好,结婚不久又有了孩子,孩子现在三岁了,在这三年里不知吵了多少会,可能现实生活就是这样的,两口子可能都吵过架,后来经过几次吵架,我也懂得了很多,两个人就的互相体谅,互相包容,忍让对方。我老公比较孩子气,动不动就发火,一点小事就生气,我们在一起这几年几乎没出去玩过,也没合过影,老公花钱也是没个计划,讲究名牌,吃也的要好的,不让买就生气要不不理你,自己老是有理的不行,我们收入一般,他的花销远远超出我们的收入,我是急在心里也不知怎么办,因为他不听你说,他还挺高傲自己认为别人都不如他,说我是傻逼,什么也不懂,真不知道你怎么长大的,就这样我也忍了,谁让我当初选的,还有为了孩子我可以忍,就是希望有一天他能发现自己也有错误,可是最近我发现我越忍让他越张狂,出去干活了,就的给你找点事干,说我出去挣钱养你们,你就不能闲着,好了你说干什么我干忍了,看见我没穿袜子说把我脚剁了,我也忍了,我不想和他吵没意思的,晚上回来饭做好了,吃了饭要吃烤红薯,我说给你弄去,需要买去,他说他姐夫说跑黑车,我说你也去吧,就这句话不爱听了,说我掉钱眼里了,就急了说我什么也不想,就会瞎BB,反正什么难听说什么,说我不干活,怎么不我不去挣钱,我说现在孩子小不能自理,我管好孩子就是我的任务,你应该出去挣钱,我说等子上学了我自然就挣去了,我说了他应该管,又不对,说凭什么我应该管你们呀,又急了就开始发疯了一直在说些他自己认为的事把我想想的特别坏,还的让你承认他说的对,我无语了不说了,让着他让他说,他又嫌你不说,我说你大人不计小人过我错了你就包容我一下吧别生气他说不行没完接着又是一顿数落,我现在都不知该如何是好,我忍让他那么多是让他从中得到点领悟,人无完人,把自己不对的也改改,发现点自己的缺点,但是没有反而更猖狂了,我又不是一个智慧的女人我现在该怎么办,希望大家帮帮忙,我很需要你们谢谢啦!



我想在用户发表该文章时,把文章的某些词语记录下来作为关键字以作他用。有没有什么算法/思路可以实现这个需求呢?还是只能人工阅读然后总结/抽出关键字?
------解决方案--------------------
1.有关键词表(可以添加)
2.计算关键词频率

不要自己做分词,呵呵
编辑(这里指的人/职位)还是需要的
------解决方案--------------------
1 系统关键字表, 会自动匹配替换关键字。
2 用户录入时指定关键字

------解决方案--------------------
说明:
1、我使用的编码是 gbk 的,如果是 utf-8 的请自行删除有关编码的部分
2、处理用的文档时楼主贴出的示例文字
3、代码是现写的,有关算法问题请指正

iconv_set_encoding("internal_encoding", "utf-8");<br>iconv_set_encoding("output_encoding", "gbk");<br>ob_start("ob_iconv_handler"); <br><br>$fn = '如何在一篇文章内拆分和匹配关键字_例文.txt';<br><br>$p = new T;<br>$ar = $p->parse($fn);<br>print_r($ar);<br>//print_r($p->dat);<br><br>class T {<br>  var $maxlen = 4;//最大组词长度<br>  var $dat = array();<br>  var $dict = array();<br>  function get($offs=0) {<br>    if($this->i + $offs >= $this->len <br><font color="#FF8000">------解决方案--------------------</font><br> $offs >= $this->maxlen) return false;<br>    $ch = $this->doc[$this->i + $offs];<br>    if(in_array($ch, $this->dict)) return false;<br>    return $ch;<br>  }<br>  function parse($filename) {<br>    $this->dict = explode('<br><font color="#FF8000">------解决方案--------------------</font><br>', iconv('gbk', 'utf-8', ',<br><font color="#FF8000">------解决方案--------------------</font><br>。<br><font color="#FF8000">------解决方案--------------------</font><br>;<br><font color="#FF8000">------解决方案--------------------</font><br>:<br><font color="#FF8000">------解决方案--------------------</font><br>“<br><font color="#FF8000">------解决方案--------------------</font><br>”<br><font color="#FF8000">------解决方案--------------------</font><br>?'));<br>    $s = file_get_contents($filename);<br>    $s = iconv('gbk', 'utf-8', $s);<br>    preg_match_all('/./u', $s, $r);<br>    $this->doc = $r[0];<br>    $this->i = 0;<br>    $this->len = count($this->doc);<br>    while($this->i len) {<br>      if(($ch = $this->get()) !== false) {<div class="clear">
                 
              
              
        
            </div>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download

Atom editor mac version download

The most popular open source editor