How to write a regular expression in php to retrieve the content in [attach] 1 [/attach ]?

Source: Internet
Author: User
Tags php write
How does php write a regular expression to retrieve the [attach] 1 [attach] content [attach] 1 [/attach] att[ attach] 2 [/attach] your part?

How to obtain the array of content 1 and 2 between [attach] [/attach]


Reply to discussion (solution)

Preg_match_all ('/[attach] (. *?) [/Attach]/I ',' [attach] 1 [/attach] [attach] 2 [/attach] ', $ out ); print_r ($ out );


Not tested!

/[attach](.*?)[\/attach]/i
Just forgot to write the escape

It seems wrong, big brother. how can I output the results?

The output is
1
2

Preg_match_all ('/\ [attach \] (. *?) \ [\/Attach \]/I ',' [attach] 1 [/attach] [attach] 2 [/attach] your ', $ out ); print_r ($ out );


I want to test it for you!

The above arrays are all out, and the rest will be done by yourself.

$ Str = "content [attach] 1 [/attach] [attach] 2 [/attach] your"; preg_match_all ('/\ [attach] (. *?) \ [\/Attach]/I ', $ str, $ ret); print_r ($ ret [1]);

Output:
Array ([0] => 1 [1] => 2)

See http://clqwtt.blog.163.com/blog/static/22351105520139155735792/

You can also use php simple_html_dom implementation, refer to: http://clqwtt.blog.163.com/blog/static/223511055201391694845458/

Preg_match_all ('/\ [attach] ([^ \ [] *) \ [\/attach]/isU', $ str, $ ret );

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.