How to match the first & lt;/p & gt; and the last & lt;/p & gt; such as the following & lt; p & gt; 1111111 & lt; /p & gt; & lt; p & gt; 2222222 & lt;/p & gt; & lt; p & gt; 33333333 & lt;/p & gt; how to match the first regular expression
And the last
For example, the article is as follows:
1111111
2222222
33333333
4444444
55555555
66666666
7777777
Matched output
1111111
In
And the last section
7777777
Of
How to get regular expressions? Share To: and the last one
] For example, the article is as follows:
1111111
2222222
33333333
4444444
55555555
666666... 'data-pics = ''>
------ Solution --------------------
Preg_match_all ('/^
. + <\/P>
------ Solution --------------------
. + <\/P> $/U', $ s, $ m );
------ Solution --------------------
$s =<<< TXT
1111111
2222222
33333333
4444444
55555555
66666666
7777777
TXT;
echo preg_replace('#()(.+)()#s', '$1aaa$2$3BBB', $s);
1111111
Aaa
2222222
33333333
4444444
55555555
66666666
7777777
BBB
Reference:
Quote: reference:
Quote: reference:
If you only want to match
You don't need regular expressions.
PHP5, no one should use PHP4 now...
$str = '1111111
2222222
33333333
4444444
55555555
66666666
7777777
';
$fp = stripos($str, '');
$first = substr($str, $fp, 4);
$ep = stripos($str, '');
$end = substr($str, $ep, 4);
Wrong, $ ep = strripos ($ str ,'
');
Brother upstairs is the same as I think.
In fact, I want to append some text at the end of the first paragraph, and add some text at the end of the last paragraph.
------ Solution --------------------
Reference:
Quote: reference:
Quote: reference:
If you only want to match
You don't need regular expressions.
PHP5, no one should use PHP4 now...
$str = '1111111
2222222
33333333
4444444
55555555
66666666
7777777
';
$fp = stripos($str, '');
$first = substr($str, $fp, 4);
$ep = stripos($str, '');
$end = substr($str, $ep, 4);
Wrong, $ ep = strripos ($ str ,'
');
Brother upstairs is the same as I think.