PHP Regular Expressions Replace site keyword links after blank problem resolution, regular expression keyword _php tutorial

Source: Internet
Author: User
Tags php regular expression

PHP Regular expression replaces the Site keyword link after blank problem resolution, regular expression keyword


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 ('/(\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 $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 problem, here is a, replace the keyword is linked to the program

I can write like this, with Ie6,firefox 3.0 have tried, no problem.



<title>New Document </TITLE></title>




</HEAD>


Xhtml Linux
</BODY>

Related Article

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.