Current Location: Home> Function Categories> mb_ereg_search

mb_ereg_search

Multi-byte regular expression matching for predefined multi-byte strings
Name:mb_ereg_search
Category:Multi-byte string
Programming Language:php
One-line Description:Perform regular expression search in multibyte string

Function name: mb_ereg_search()

Applicable version: PHP 4 >= 4.2.0, PHP 5, PHP 7

Function Description: The mb_ereg_search() function is used to perform regular expression searches in a multibyte string.

Usage: mb_ereg_search($pattern, $string, $option = 'ms')

parameter:

  • $pattern: The regular expression pattern to search for.
  • $string: The multibyte string to search for.
  • $option (optional): The available options are as follows:
    • 'ms': Default option, indicating the use of multibyte string and multi-line mode.
    • 'is': means that only multibyte strings are used.
    • 'ix': means using multibyte strings and ignoring case.
    • 'imsx': means using multibyte strings, multi-line modes, and ignoring case.

Return value:

  • Returns TRUE if a match is found, otherwise returns FALSE.

Example:

 // 在字符串中搜索匹配的正则表达式$string = "Hello, 你好!"; $pattern = "/[\x{4e00}-\x{9fa5}]/u"; // 匹配中文字符mb_ereg_search($pattern, $string); if (mb_ereg_search()) { echo "找到匹配项!"; } else { echo "未找到匹配项!"; } // 使用不同选项进行搜索$string = "Hello, 你好!"; $pattern = "/hello/i"; // 忽略大小写匹配"hello" mb_ereg_search($pattern, $string, 'i'); if (mb_ereg_search()) { echo "找到匹配项!"; } else { echo "未找到匹配项!"; }

Notes:

  • Before using the mb_ereg_search() function, you must first use the mb_ereg() function or the mb_ereg_search_init() function to set the regular expression pattern.
  • After using the mb_ereg_search() function, you can use the mb_ereg_search_getpos() function to get the position of the match.
Similar Functions
Popular Articles