- $ KeywordArray = array (
- Array ('process', 'http: // www.01happy.com/linux-ps-view-process /')
- , Array ('daem', 'http: // www.01happy.com/linux-python-daemon /')
- );
You can use the built-in usort function to sort two-dimensional arrays. the code is as follows:
- Usort ($ keywordArray, function ($ a, $ B ){
- $ Al = strlen ($ a [0]);
- $ Bl = strlen ($ B [0]);
- If ($ al = $ bl)
- Return 0;
- Return ($ al> $ bl )? -1: 1;
- });
Extract all html tags
- Preg_match_all ('/<\/? [A-zA-Z] + [^>] *>/', $ content, $ match );
- If (isset ($ match [0]) {
- $ HtmlTagArray = $ match [0];
- }
Here, the regular expression is extracted from the contents of the <> package. I believe that all content that needs to be displayed as the <> number should be replaced by escape characters <& gt, all <> contents can be considered as tags. In fact, the same is true for browsers. many online text editors automatically escape these characters. Split the content and save it to an array.$ NoTagContentArray = preg_split ('/<\/? [A-zA-Z] + [^>] *>/', $ content ); The regular expression used here is the same as the regular expression used to extract html tags. Array of cyclically split content, replacing the keyword linkThe processing method here is to replace the keyword with the md5 value, and then the md5 value with the link keyword. the reason for this is to solve the problem of inclusion between keywords. In addition, I have considered the split content array implode into a string, so there is no need to replace it cyclically. However, I am worried that the strings after implode will form keywords in the concatenation, so this is not the case. Combine extracted html tags and processed contentThis step is relatively simple, and it will be OK after splicing. The length of the html tag array is 1 less than that of the split content array. Therefore, you must use isset to determine the length of the tag. The above content has been tested for many times. if you have any questions, please join the QQ group on this site: 161228069 for communication. |