php - line break on regular expressions -


i'm trying replace between 2 tags, i'm not able build right expression.

this did: /<tag>(.*|\n*)</tag>/

i want capture characters including line breaks.

this example of need capture:

 <tag>        <div class="feed_title">some title</div>        <div class="feed_content">some text</div>     </tag> 

can of tell me i'm doing wrong?

here link regexr , full example of content looks like: http://regexr.com?2t4n1

'#.#m' 

the m means multiline, makes point able match newlines=line breaks \n

edit:

as has been corrected sharp eyes , brain, evidently '#.+#s'

edit2:

as michael goldshteyn said, should work

$ch = '<tag>\s+<div class="feed_title">some title</div>\s+<div class="feed_content">some text</div>\s+</tag>'  preg_match('#<tag>(.+?)</tag>#s',$ch,$match) 

there solution, without s flag, think:

preg_match('#<tag>((.|\s)+?)</tag>#',$ch,$match) 

but it's more complicated

.

edit 3:

i think presence of \s in $ch nonsense. \s used in re, not in strings.

i wrote because thinking blanks or \t before <tag> , @ beginning of other lines

\t written escape; that's not reason write \s in string


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -