How does PHP match and replace the data outside the img tag? The img data remains unchanged.

Source: Internet
Author: User
When I add an article, I need to automatically generate the anchor text. When the keyword matches the content of the article, the alt and title values of img will be matched, and an exception will occur in the image. Please help me solve it! Thank you! What I originally wanted was & amp; lt; p & amp; gt; & amp; lt; imgtitle & #039; xxx & #039; & amp; gt; link these words... when I add an article, I need to automatically generate the anchor text. When the keyword matches the content of the article, the alt and title values of img will be matched, and an exception will occur in the image.
Please help me solve it! Thank you!

What I originally wanted was

Add links to these texts


Error content:

My code is written as follows:

/*** Replace multiple keywords, replace each time * @ param Mixed $ search finds the target value * @ param Mixed $ replace the replacement value * @ param Mixed $ subject executes the replacement string/array * @ param Int $ limit allows replacement times, default Value:-1, unlimited number of times * @ 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 the anchor text. When the keyword matches the content of the article, the alt and title values of img will be matched, and an exception will occur in the image.
Please help me solve it! Thank you!

What I originally wanted was

Add links to these texts


Error content:

My code is written as follows:

/*** Replace multiple keywords, replace each time * @ param Mixed $ search finds the target value * @ param Mixed $ replace the replacement value * @ param Mixed $ subject executes the replacement string/array * @ param Int $ limit allows replacement times, default Value:-1, unlimited number of times * @ 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 you see the code?

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.