The title is not known to be suitable. The specific situation is this: the site to increase the keyword link function, and then need to the content of the article regular expression matching and replace, and then use the Preg_replace function. Replace the program code as follows:
function Replacekeyword ($linkDefs, $content) {$linkMap = array (); /*foreach ($linkDefs as $row) { $linkMap [] = Explode (', ', $row);} */$linkMap = $linkDefs; //Replace the original link with the text foreach ($linkMap as $row) { $content = Preg_replace ('/(<a.*?>\s* ) ('. $row [0]. ') (\s*<\/a>)/sui ', $row [0], $content);} //keywords from long to short sort usort ($linkMap, ' _sortdesc ');//var_dump ($linkMap); $tmpKwds = Array (); Store temporarily replaced sub-keywords $k _count=0;foreach ($linkMap as $i = = $row) { list ($KWD, $url) = $row; for ($j = $i +1; $j <count ($LINKMAP); $j + +) { $subKwd = $linkMap [$j][0]; //If other keywords are included, temporarily replace them with other strings, such as tea into if (Strpos ($KWD, $SUBKWD )!== false) { $TMPKWD = "; $KWD = Str_replace ($SUBKWD, $TMPKWD, $KWD); $tmpKwds [$tmp KWD] = $subKwd; } } //Replace the text with the link require (mleinc. ' /config/globals.config.php '); $th _num = $config [' Keyword_num ']; //keyword substitutions $content = Preg_replace ('/('. $row [0]. ') /sui ', '<a href= "'. $row [1]. '" > '. $kwd. ' </a> ', $content, $th _num, $count); //all matches will be replaced $k _count+= $count;} //Replace the string in place of the sub-key back to 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 is from the Internet, and then the local test is normal, the local environment for PHP 5.3 service is 5.2, uploaded to the Internet, the submission is blank, the first consideration is the PHP version of the problem, thought to be ereg preg difference, after the replacement or not. Later on-line to see, found that a netizen said adjust the big pcre.backtrack_limit and Pcre.recursion_limit on the line, I tried the next, sure enough. Seems to be a configuration problem, but in general, the default configuration of PHP should be no problem, I wrote this program is not good enough!
PHP Regular expression replaces the Site keyword link after blank problem resolution