trie 的应用
应 CSDN 要求,收到 CSDN 月饼的应发散分贴
前贴已发,由于僧多粥少。故此结贴,比继续发帖散分
class TTrie {<br /> protected $buffer = array();<br /> protected $dict = array( array() );<br /> protected $input = 0; //字符串当前偏移<br /> protected $backtracking = 0; //字符串回溯位置<br /> public $debug = 0;<br /> public $savematch = 1;<br /> <br /> function set($word, $action='') {<br /> if(is_array($word)) {<br /> foreach($word as $k=>$v) $this->set($k, $v);<br /> return;<br /> }<br /> $p = count($this->dict);<br /> $cur = 0; //当前节点号<br /> foreach(str_split($word) as $c) {<br /> if (isset($this->dict[$cur][$c])) { //已存在就下移<br /> $cur = $this->dict[$cur][$c];<br /> continue;<br /> }<br /> $this->dict[$p]= array(); //创建新节点<br /> $this->dict[$cur][$c] = $p; //在父节点记录子节点号<br /> $cur = $p; //把当前节点设为新插入的<br /> $p++;<br /> }<br /> $this->dict[$cur]['acc'] = $action; //一个词结束,标记叶子节点<br /> }<br /> <br /> function match($s) {<br /> $ret = array();<br /> $cur = 0; //当前节点,初始为根节点<br /> $i =& $this->input; //字符串当前偏移<br /> $p =& $this->backtracking; //字符串回溯位置<br /> $s .= "\0"; //附加结束符<br /> $len = strlen($s);<br /> $buf = '';<br /> while($i < $len) {<br /> $c = $s{$i};<br /> if(isset($this->dict[$cur][$c])) { //如果存在<br /> $cur = $this->dict[$cur][$c]; //转到对应的位置<br /> if(isset($this->dict[$cur][$s[$i+1]])) {//检查下一个字符是否也能匹配,长度优先<br /> $i++;<br /> continue;<br /> }<br /> if(isset($this->dict[$cur]['acc'])) { //是叶子节点,单词匹配!<br /> if($buf != '') {<br /> $this->buffer[] = $buf;<br /> $buf = '';<br /> }<br /> if($this->savematch) $this->buffer[] = substr($s, $p, $i - $p + 1); //取出匹配位置和匹配的词<br /> <br /> $ar = explode(',', $this->dict[$cur]['acc']);<br /> call_user_func_array( array($this, array_shift($ar)), $ar );<br /> <br /> $p = $i + 1; //设置下一个回溯位置<br /> $cur = 0; //重置当前节点为根节点<br /> }<br /> } else { //不匹配<br /> $buf .= $s{$p}; //substr($s, $p, $i - $p + 1); //保存未匹配位置和未匹配的内容<br /> $cur = 0; //重置当前节点为根节点<br /> $i = $p; //把当前偏移设为回溯位置<br /> $p = $i + 1; //设置下一个回溯位置<br /> }<br /> $i++; //下一个字符<br /> }<br /> if(trim($buf, "\0")) $this->buffer[] = trim($buf, "\0");<br /> }<br /> <br /> function __call($method, $param) {<br /> if($this->debug) printf("偏移:%d 回溯:%d\n", $this->input, $this->backtracking);<br /> <br /> }<br /> }<br />
------解决方案--------------------
这个是国庆中秋过节的福利么。。。
------解决方案--------------------

老大在各应我没发散分帖啊?哈哈 ...话说我早发到水区去了.嘿嘿
继续接分
------解决方案--------------------
初学绝对很有用
------解决方案--------------------
接分~~~~
是哪家的月饼啊
------解决方案--------------------
我看不到懂样
------解决方案--------------------

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

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.
