Php adds a span tag to a group of specified keywords. span tag _ PHP Tutorial

Source: Internet
Author: User
Php adds a span tag to a group of specified keywords. Php adds a span tag to a group of specified keywords. This article describes how php adds a span tag to a group of specified keywords. Share it with you for your reference. For example, php adds a span tag to a group of specified keywords.

This example describes how php adds a span tag to a set of specified keywords. Share it with you for your reference. The details are as follows:

In this example, php adds a span tag to a group of specified keywords to highlight and highlight keywords.

// Example use: $spanned = codeWords($string_containing_keywords);// My site: andrew.dx.am// Using colour==blue, but different arrays of words and different // colours can be added.function onlyWholeWords(&$value, $key) {// Ignores words after // 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 = "$1" . $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',  'this', 'to', 'typeof', 'until',  'var', 'void', 'while', 'with');  $keywords2 = $keywords;  array_walk($keywords, 'onlyWholeWords');  array_walk($keywords2, 'addSpan', 'blue');  $code = preg_replace($keywords, $keywords2, $code);  return $code;}

I hope this article will help you with php programming.

Examples in this article describes how php adds a span tag to a set of specified keywords. Share it with you for your reference. For details, see...

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.