The problem of blank space after PHP regular expression replacement site keyword link is solved. The regular expression keyword
title is not suitable or not. The specific situation is this: the website wants to add a keyword link function, and then the content of the article needs to be matched and replaced with regular expressions, and then the preg_replace function is used. The replaced program code is as follows:
function ReplaceKeyword($linkDefs,$content){
$linkMap = array();
/*foreach($linkDefs as $row) {
$linkMap[] = explode(',', $row);
}*/
$linkMap = $linkDefs;
//Replace the original link with text
foreach($linkMap as $row) {
$content = preg_replace('/(
s*)('.$row[0].')(s*)/sui', $row[0], $ content);
}
//Sort keywords from longest to shortest
usort($linkMap, '_sortDesc');
//var_dump($linkMap);
$tmpKwds = array(); //Storage temporarily replaced sub-keywords
$k_count=0;
foreach($linkMap as $i=>$row) {
list($kwd, $url) = $row;
for($j=$i+1; $j'.$kwd.' a>', $content, $th_num ,$count); // All matching items will be replaced
$k_count+=$count;
}
//Replace the string that replaces the subkeyword back
foreach($tmpKwds as $tmp=>$kwd) {
$content = str_replace($tmp, $kwd, $content);
}
$result = array($content,$k_count);
return $result;
unset($result);
unset($tmp);
unset($tmpKwds);
unset($kwd);
unset($count);
unset($config);
unset($linkMap);
unset($linkDefs);
unset($tmpKwd);
unset($content);
unset($th_num);
unset($row);
unset($k_count);
}
The program was found online and tested locally. It was normal. The local environment was PHP 5.3 and the service was 5.2. After uploading it to the Internet, the submission showed blank. At first, I thought it was a PHP version problem and thought it was the difference between ereg and preg. , it still doesn’t work after replacement. Later, when I looked online, I found that some netizens said that just adjusting the pcre.backtrack_limit and pcre.recursion_limit would be enough. I tried it, and it worked. It seems to be a configuration problem, but under normal circumstances, the default configuration of PHP should be fine. The program I wrote myself is still not good enough!
I can write like this. I have tried it with IE6 and FIREFOX 3.0, and there is no problem.
New Document < ;/TITLE>
Xhtml Linux
< ;/BODY>
The following is the innerHTM of BODY obtained through FIREFOX 3.0
< font color="red"> ">x
Latest Articles by Author
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Latest Issues
-
2025-03-26 19:48:00
-
2025-03-26 19:40:08
-
2025-03-26 12:24:37
-
2025-03-26 12:20:46
-
2025-03-21 13:39:34