How can I 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] Dashuai mansion [attach] 2 [/attach] & nbsp; how do you get the content between [attach] [/attach] 1 and 2., preg_match_all ('/[attach] (. *?) [/A php: how to write a regular expression to retrieve the content in [attach] 1 [/attach]
Content [attach] 1 [/attach] Dashuai Fu [attach] 2 [/attach] your

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

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


Not tested!
------ Solution --------------------
/[attach](.*?)[\/attach]/i
Just forgot to write the escape
------ Solution --------------------

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


I want to test it for you!


------ Solution --------------------
The above arrays are all out, and the rest will be done by yourself.
------ Solution --------------------
$ Str = "content [attach] 1 [/attach] [attach] 2 [/attach] your ";
Preg_match_all ('/\ [attach] (. *?) \ [\/Attach]/I ', $ str, $ ret );
Print_r ($ ret [1]);

------ Solution --------------------
Output:
Array ([0] => 1 [1] => 2)
------ Solution --------------------
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/
------ Solution --------------------
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.