php关键词拦截程序,拦截后怎么知道哪个词为非法词组?
一、panduan.php
/**
* 判断文本中是否存在关键词
*/
function filter_text($text, $badstring){
$filter = explode('|', $badstring);
foreach ($filter as $key) {
if(strpos($text, $key) !== false){
return true;
}
}
return false;
}
?>
二、filter.php
$badstring="拦我|此内容|不允许";
?>
三、index.php
require_once("panduan.php");
require_once("filter.php");
$biaoti="如果包含此内容就不能通过!";
if(filter_text($biaoti, $badstring)){
echo "对不起,你提示的内容包含“$*****”文字不能表,请删除“此内容”文字后再提交!";
exit();
}
?>
以上代码能正确拦截事先设置好的关键词,但怎么写才能提示是哪个关键词非法的?如果取得引号中的内容:“$*****”?
请高手帮忙,谢谢!
------解决方案--------------------
在这里修改成
if(strpos($text, $key) !== false){
return $key;
}
这里
if(filter_text($biaoti, $badstring)){
echo "对不起,你提示的内容包含“$*****”文字不能表,请删除“此内容”文字后再提交!";
exit();
}
修改成
$badstr=filter_text($biaoti, $badstring);
if($badstr){
echo "对不起,你提示的内容包含“.$badstr.”文字不能表,请删除“此内容”文字后再提交!";
exit();
}
大约如此.
------解决方案--------------------
- PHP code
$text = '拦我'; $badstring = "/拦我|此内容|不允许/"; if (preg_match($badstring, $text, $matchs)){ echo $matchs[0]; //var_dump($matchs); } <br><font color="#e78608">------解决方案--------------------</font><br> <strong>关于二者的效率</strong><br><br>测试代码:<br>
- PHP code
$start = microtime(true); $text = '拦我'; $badstring = "/拦我|此内容|不允许/"; $count = 0; for($i = 0; $i

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)

phpisusedforsenderemailsduetoitsbuilt-inmail()函数andsupportiveLibrariesLikePhpMailerandSwiftMailer.1)usethemail()functionforbasicemails,butithasimails.2)butithasimimitations.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显着提升PHP应用的性能。

依赖性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增强量产生性,可验证性和Maintainability.itallowspasspassingDepentenciesLikEdenceSeconnectionSeconnectionStoclasseconnectionStoclasseSasasasasareTers,interitationApertatingAeseritatingEaseTestingEasingEaseTeStingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

禅工作室 13.0.1
功能强大的PHP集成开发环境

WebStorm Mac版
好用的JavaScript开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6
视觉化网页开发工具