Home >Backend Development >PHP Tutorial >求php从一段字符串中截取指定内容的正则表达式代码解决方案

求php从一段字符串中截取指定内容的正则表达式代码解决方案

WBOY
WBOYOriginal
2016-06-13 10:26:09883browse

求php从一段字符串中截取指定内容的正则表达式代码
字符串是这样的 fhghfghdfpostm|a:2:{i:5;i:0;i:2;i:0;}dsfdsdfsd

也可能是fhghfsdfsdfgdfgdfgdfgghdfpostm|a:2:{i:5;i:0;i:2;i:0;i:0;i:0;i:0;}dsfdsdfsdsdfsdfgsdgsdg

我想要截取其中的 postm|a:2:{i:5;i:0;i:2;i:0;}或者postm|a:2:{i:5;i:0;i:2;i:0;i:0;i:0;i:0;} 但是这个字符串的长度不固定 求代码

------解决方案--------------------

PHP code
$s = 'fhghfsdfsdfgdfgdfgdfgghdfpostm|a:2:{i:5;i:0;i:2;i:0;i:0;i:0;i:0;}dsfdsdfsdsdfsdfgsdgsdg';echo preg_replace('/.*(postm.+\}).*/', '$1', $s);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn