Php adds hyperlinks to html text keywords. -Php Tutorial

Source: Internet
Author: User
Php adds hyperlinks to html text keywords. We usually use regular expressions to replace a keyword with a hyperlink.
However, the problem arises. the keywords in alt in the image are replaced with links. Text with hyperlinks is also replaced.
For example, if a computer is used and the keyword is "computer", this item should not have been replaced, and the result is also replaced.
For example, if the keyword is a computer word, this word should not have been replaced. as a result, the computer word is also replaced with a hyperlink.

Computers can improve work efficiency

Note: to automatically add a hyperlink to the word "computer", such

Computers can improve work efficiency


Note: You do not want to add a hyperlink to your computer.
Note: You do not want to add a hyperlink to your computer.
Please give me some advice.


Reply to discussion (solution)

Give a thought

$ S = <TXT

Computers can improve work efficiency

Note: to automatically add a hyperlink to the word "computer", such

Computers can improve work efficiency

Note: do not want "computer" text plus hyperlink note: do not want computer text plus hyperlink TXT; $ p = '/((? : ^ |> ).*?) (Computer) ([^ <] * (? : <(?! \/A) | $)/is '; echo preg_replace ($ p,' $1 [$2] $ 3', $ s );

[Computer] can improve work efficiency

Note: to automatically add a hyperlink to the word "computer", such

Computers can improve work efficiency


Note: You do not want to add a hyperlink to "computer ".
Note: You do not want to add a hyperlink to the [computer ].

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.