How to highlight multiple keywords related to regular expression replacement-php Tutorial

Source: Internet
Author: User
Multiple key words for regular expression replacement highlight PHPcode $ karray (& quot; I & quot;, & quot; n & quot;); $ row & quot; iphone & quot ;; $ rowpreg_replace (& quot; ($ k [0]) I & quot;, & quot; & lt; fontcolorred & gt; & lt; B & gt; \ 1 & lt; B & gt; & regular expression replacement question multiple keywords highlighted
PHP code
  $ K = array ("I", "n"); $ row = "iphone"; $ row = preg_replace ("/($ k [0])/I ","\ 1", $ Row); $ row = preg_replace ("/($ k [1])/I ","\ 1", $ Row); echo $ row; // output nt color = red> int> phone // How can I change the keyword, that is, the letter in $ k, to red? Do not replace?


------ Solution --------------------
PHP code
$ K = array ("I", "n"); $ p = join ('', $ k); $ row =" iphone "; echo preg_replace ("/[". $ p. "]/I ","\ 0", $ Row );

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.