Forum Moderators: coopster

Message Too Old, No Replies

Regular Expression Help with New Lines

         

kazisdaman3

12:25 pm on Jun 2, 2007 (gmt 0)

10+ Year Member


Hi there, thanks for reading this!

Trying to create a regular expression that grabs everything inside of

[quote]
text
[/quote]

I can do it with preg_replace("/\[quote\](.*?)\[\/quote\]/", $var,$var);

but it doesn't do it with new lines, any help would be much appreciated been trying to figure this out for hours now.

Thank You,
Wesley

eelixduppy

12:38 pm on Jun 2, 2007 (gmt 0)



Try changing the pattern to something like this:

$pattern = "/\[quote\](.*?)\[\/quote\]/s";

Notice the use of the 's' pattern modifier: [php.net...]

kazisdaman3

2:52 pm on Jun 2, 2007 (gmt 0)

10+ Year Member



Ok thanks that worked perfect!

I just ran into another small change, wouldn't I add like an! if I wanted it to do it to have it only do it when something does not appear.

Like:

original - /\[quote\](.*?)\[\/quote\]/s

modified - /\[quote\](!\[quote\])(.*?)\[\/quote\]/s

only do it when there is NO [quote] inside the two open and close quote brackets?

Thanks again appreciate your help

eelixduppy

3:22 pm on Jun 3, 2007 (gmt 0)



You mean something like this?

$pattern = "/\[quote\]([^\[quote\]]+)\[\/quote\]/";

[php.net...]

kazisdaman3

10:23 am on Jun 4, 2007 (gmt 0)

10+ Year Member



Hey Thanks eelixduppy,

I was just having some problems, although your first formula was correct I just needed to add an loop to it for my particular purpose. Thanks aton eelixduppy again for like the 6th time!

eelixduppy

1:18 pm on Jun 4, 2007 (gmt 0)



So you're good, now, right? Your solution has been found? :)