How PHP adds a span tag to a specified set of keywords, span tab _php Tutorial

Source: Internet
Author: User

The method by which PHP adds a span tag to a specified set of keywords, the span tag


This example describes how PHP adds a span tag to a specified set of keywords. Share to everyone for your reference. Specific as follows:

This is PHP to a set of keywords to add a span tag, highlighting keywords

Example use: $spanned = codewords ($string _containing_keywords);//My site:andrew.dx.am//Using colour==blue, but Diffe Rent arrays of words and different//colours can be added.function onlywholewords (& $value, $key) {//ignores words AF ter//Comment delimiters.//$value = "/\b (". $value.  ") \b/"; doesn ' t handle comments//$value = "/^ (?:(?! \/\/).) *\k\b (". $value. ") \b/"; \k Lookbehind Alternative is not supported in PHP < 5.2.4, so use: $value = "/^ (?:(?! \/\/).) *) \b ". $value. "\b/";} Function Addspan (& $value, $key, $color = ' blue ') {$value = "$" . $value. "";} function codewords ($code) {$keywords = array (' As ', ' break ', ' case ', ' class ', ' Continue ', ' default ', ' Do ', ' elif ', ' else ', ' ElseIf ', ' for ', ' foreach ', ' function ', ' if ', ' new ', ' null ', ' return ', ' self ', ' switch ', ' the ', ' to ', ' typeof ', ' U '  Ntil ', ' var ', ' void ', ' while ', ' with ');  $keywords 2 = $keywords;  Array_walk ($keywords, ' onlywholewords ');  Array_walk ($keywords 2, ' Addspan ', ' Blue ');  $code = Preg_replace ($keywords, $keywords 2, $code); return $code;}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/976688.html www.bkjia.com true http://www.bkjia.com/PHPjc/976688.html techarticle The method by which PHP adds a span tag to a specified set of keywords, a span tag this article describes how PHP adds a span tag to a specified set of keywords. Share to everyone for your reference. Specific as ...

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