比如文章如下
e388a4556c0f65e1904146cc1a846bee111111194b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846bee222222294b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846bee3333333394b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846bee444444494b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846bee5555555594b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846bee6666666694b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846bee777777794b3e26ee717c64999d7867364b1b4a3
匹配出e388a4556c0f65e1904146cc1a846bee1111111 94b3e26ee717c64999d7867364b1b4a3中的94b3e26ee717c64999d7867364b1b4a3
和最后一段e388a4556c0f65e1904146cc1a846bee7777777 94b3e26ee717c64999d7867364b1b4a3的94b3e26ee717c64999d7867364b1b4a3
正则如何弄?
preg_match_all('/^e388a4556c0f65e1904146cc1a846bee.+8a45c867fd727fc770712bce9321033f|e388a4556c0f65e1904146cc1a846bee.+8a45c867fd727fc770712bce9321033f$/U',$s,$m);
preg_match_all('/^e388a4556c0f65e1904146cc1a846bee.+8a45c867fd727fc770712bce9321033f|e388a4556c0f65e1904146cc1a846bee.+8a45c867fd727fc770712bce9321033f$/U',$s,$m);
这样匹配到的是整一段了
我要的只是一个94b3e26ee717c64999d7867364b1b4a3
preg_match_all('/^e388a4556c0f65e1904146cc1a846bee.+(8a45c867fd727fc770712bce9321033f)|e388a4556c0f65e1904146cc1a846bee.+(8a45c867fd727fc770712bce9321033f)$/U',$s,$m);
$s =<<< TXT<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>TXT;preg_match('#(</p>).+(</p>)#s', $s, $r);print_r($r);Array
如果只是想要匹配 94b3e26ee717c64999d7867364b1b4a3的话,可以不用正则吧。
PHP5,现在应该没有谁用PHP4吧。。。
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
别用正则了
<?php $s='<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';print strlen($s);print stripos($s,'</p>');print strripos($s,'</p>');?>运行结果:11310109
如果只是想要匹配 94b3e26ee717c64999d7867364b1b4a3的话,可以不用正则吧。
PHP5,现在应该没有谁用PHP4吧。。。
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
如果只是想要匹配 94b3e26ee717c64999d7867364b1b4a3的话,可以不用正则吧。
PHP5,现在应该没有谁用PHP4吧。。。
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
$s =<<< TXT<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>TXT;echo preg_replace('#(</p>)(.+)(</p>)#s', '$1aaa$2$3BBB', $s);e388a4556c0f65e1904146cc1a846bee111111194b3e26ee717c64999d7867364b1b4a3 aaa
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
如果只是想要匹配 94b3e26ee717c64999d7867364b1b4a3的话,可以不用正则吧。
PHP5,现在应该没有谁用PHP4吧。。。
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
如果只是想要匹配 94b3e26ee717c64999d7867364b1b4a3的话,可以不用正则吧。
PHP5,现在应该没有谁用PHP4吧。。。
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
<?php $s='<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';print strlen($s);$find = '</p>';$find_len = 4; //</p> 长度$s = substr_replace($s, $find."第一个p", stripos($s,'</p>'), $find_len);$s = substr_replace($s, $find."最后一个p", strripos($s,'</p>'), $find_len);print $s;
如果只是想要匹配 94b3e26ee717c64999d7867364b1b4a3的话,可以不用正则吧。
PHP5,现在应该没有谁用PHP4吧。。。
$str = '<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';$fp = stripos($str, '</p>');$first = substr($str, $fp, 4);$ep = stripos($str, '</p>');$end = substr($str, $ep, 4);
<?php $s='<p>1111111</p><p>2222222</p><p>33333333</p><p>4444444</p><p>55555555</p><p>66666666</p><p>7777777</p>';print strlen($s);$find = '</p>';$find_len = 4; //</p> 长度$s = substr_replace($s, $find."第一个p", stripos($s,'</p>'), $find_len);$s = substr_replace($s, $find."最后一个p", strripos($s,'</p>'), $find_len);print $s;