How PHP matches the data outside the IMG tag and replaces it with the IMG data unchanged

Source: Internet
Author: User
When I add an article, I need to automatically generate anchor text, keyword to match the content of the article, will match to the IMG alt and title value, the picture will appear abnormal.
Dear God, help me solve it! Thanks, man.

The original wanted is

这些文字加链接


Error content:

My code is written like this:

/** * 多关键词替换,每个替换一次 * @param  Mixed $search   查找目标值 * @param  Mixed $replace  替换值 * @param  Mixed $subject  执行替换的字符串/数组 * @param  Int   $limit    允许替换的次数,默认为-1,不限次数 * @return Mixed */function str_replace_limit($search, $replace, $subject, $limit=-1){    if(is_array($search)){        foreach($search as $k=>$v){            $search[$k] = '`'. preg_quote($search[$k], '`'). '`';        }    }else{        $search = '`'. preg_quote($search, '`'). '`';    }    return preg_replace($search, $replace, $subject, $limit);}foreach ($keylink as $k){        $keyArray[] = $k->word;        $url = 'url.'" style="color:red;font-size:1.2em;">'.$k->word.'';        $replacement[] = $url;}

Reply content:

When I add an article, I need to automatically generate anchor text, keyword to match the content of the article, will match to the IMG alt and title value, the picture will appear abnormal.
Dear God, help me solve it! Thanks, man.

The original wanted is

这些文字加链接


Error content:

My code is written like this:

/** * 多关键词替换,每个替换一次 * @param  Mixed $search   查找目标值 * @param  Mixed $replace  替换值 * @param  Mixed $subject  执行替换的字符串/数组 * @param  Int   $limit    允许替换的次数,默认为-1,不限次数 * @return Mixed */function str_replace_limit($search, $replace, $subject, $limit=-1){    if(is_array($search)){        foreach($search as $k=>$v){            $search[$k] = '`'. preg_quote($search[$k], '`'). '`';        }    }else{        $search = '`'. preg_quote($search, '`'). '`';    }    return preg_replace($search, $replace, $subject, $limit);}foreach ($keylink as $k){        $keyArray[] = $k->word;        $url = 'url.'" style="color:red;font-size:1.2em;">'.$k->word.'';        $replacement[] = $url;}

Can look at the code is not

  • 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.