伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: mb_ereg_search_setpos

来源:网络转载 浏览:25145次 时间:2024-03-08
mb_ereg_search » « mb_ereg_search_regs
  • PHP 手册
  • 函数参考
  • 国际化与字符编码支持
  • 多字节字符串
  • 多字节字符串 函数

mb_ereg_search_setpos

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

mb_ereg_search_setpos — Set start point of next regular expression match

说明

mb_ereg_search_setpos(int $offset): bool

mb_ereg_search_setpos() sets the starting point of a match for mb_ereg_search().

参数

offset

The position to set. If it is negative, it counts from the end of the string.

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
7.1.0 Support for negative offsets has been added.

注释

注意:

mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。

参见

  • mb_regex_encoding() - Set/Get character encoding for multibyte regex
  • mb_ereg_search_init() - Setup string and regular expression for a multibyte regular expression match
add a note

User Contributed Notes 1 note

up down -1 phpnet at osps dot net8 months ago This method, like mb_ereg_search_pos, appears to use byte offsets, not character offsets. This seems counter intuitive for the mb_* methods, which inherently take a "character" view of strings, as opposed to a "byte" based view. Even the mb_strpos method returns a character offset.

The following code reveals this byte-oriented behaviour:

<?php
    $x = 'abc456789'. "\u{1000}" .'abc4567890';
    $re = 'ab.';
    echo 'x='. $x .PHP_EOL;
    echo 're='. $re .PHP_EOL;
    mb_ereg_search_init( $x );
    mb_internal_encoding( mb_detect_encoding( $x) );
    echo 'mb_strlen='. mb_strlen( $x ) .PHP_EOL;
    echo 'strlen='. strlen( $x ) .PHP_EOL;
    foreach ( array( 0, 9, 10, 11, 12, 13 ) as $o ) {

        mb_ereg_search_setpos( $o );
        echo 'Offset='. $o
            .' mb_substr='. mb_substr( $x, $o )
            .' substr='. substr( $x, $o )
            .' mb_ereg_search_regs='. print_r( mb_ereg_search_regs( $re ), true  )
            .PHP_EOL;
    }

?>
With character offsets, we would expect offsets 11 and above to return no search result, whereas what we see is:

<?php

=abc456789ကabc4567890
re=ab.
mb_strlen=20
strlen=22
Offset=0 mb_substr=abc456789ကabc4567890 substr=abc456789ကabc4567890 mb_ereg_search_regs=Array
(
    [0] => abc
)

Offset=9 mb_substr=ကabc4567890 substr=ကabc4567890 mb_ereg_search_regs=Array
(
    [0] => abc
)

Offset=10 mb_substr=abc4567890 substr=��abc4567890 mb_ereg_search_regs=Array
(
    [0] => abc
)

Offset=11 mb_substr=bc4567890 substr=�abc4567890 mb_ereg_search_regs=Array
(
    [0] => abc
)

Offset=12 mb_substr=c4567890 substr=abc4567890 mb_ereg_search_regs=Array
(
    [0] => abc
)

Offset=13 mb_substr=4567890 substr=bc4567890 mb_ereg_search_regs=
?>
add a note

官方地址:https://www.php.net/manual/en/function.mb-ereg-search-setpos.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net