Solve the blank problem after replacing the site keyword link with a regular expression in PHP. tutorial on regular expression keyword _ PHP

Source: Internet
Author: User
Tags php regular expression
The PHP regular expression replaces the site keyword link and then solves the blank problem. The regular expression keyword. The PHP regular expression replaces the site keyword link with a blank space to solve the problem. The regular expression keyword title does not know whether it is appropriate or not. The specific situation is as follows: the website needs to add a PHP regular expression to replace the site keyword link. The problem is solved after the link is blank. the regular expression keyword

The title is inappropriate. The specific situation is as follows: the website needs to add the keyword link function, then it needs to match and replace the content of the article with a regular expression, and then uses the preg_replace function. 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 the text foreach ($ linkMap as $ row) {$ content = preg_replace ('/(\ s *)('. $ row [0]. ') (\ s * <\/a>)/sui', $ row [0], $ content);} // sort usort ($ linkMap, '_ sortDesc'); // var_dump ($ linkMap); $ tmpKwds = array (); // store the temporarily replaced subkeyword $ k_count = 0; foreach ($ linkMap as $ I =>$ row) {list ($ kwd, $ url) = $ row; for ($ j = $ I + 1; $ j $ 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 found on the Internet, and then tested locally. the local environment serves php 5.3 as 5.2. after uploading the program to the Internet, it is blank when submitted, the first consideration was the PHP version. I thought it was the difference between ereg preg and it would not work after replacement. Later, I checked it online and found that some netizens said they could adjust the large pcre. backtrack_limit and pcre. recursion_limit. I tried it and it was okay. It seems to be a configuration problem, but in general, the default configuration of PHP should be no problem, I wrote this program is still not good enough!

Php regular expression problem. Below is a program that replaces the keyword with the link

I can write it like this. I tried IE6 and FIREFOX 3.0. No problem.



New Document </TITLE>




</HEAD>


Xhtml Linux
</BODY>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.