How does a regular match the first </p> and the last </p>

Source: Internet
Author: User
How the regular matches the first one.

And the last one


such as the article below

1111111


2222222


33333333


4444444


55555555


66666666


7777777



Match out

1111111

In the


And the last paragraph

7777777

Of


How do you get it?

Share to:


------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


References:
Quote: References:

Quote: References:

If you just want to match

, you can use the regular.
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);



Wrongly written, $ep = Strripos ($str, '

');
The upstairs brothers and I want to be the same.


Actually, I want the first paragraph. Append some text, and the last paragraph to append some text

------Solution--------------------
reference:
Quote: reference:
Quote: reference:

If you just want to match

If you want, you can use the regular.
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);


was incorrectly written, $ep = Strripos ($str, '

'); The
upstairs brothers and I think the same.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.