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