Regex/pregmatch question?

Tigratrus

Well-known member
Can anyone help me nail down the syntax for a preg_match to pull the BBCode out of the raw post content in the DB field?

It's gotta be pretty close to:

preg_match('/\[img(=(.*?))?\](.*?)\[\/img\]/', $subject, $results);

At least I *think* so, I'm not even vaguely a regexian ;).

Any help would be greatly appreciated!

James
 

Wait... Suddenly remembered that Jaxel is doing this in XenPorta.

preg_match('#\[img\](.+?)\[/img\]#i', $post['message'], $matches)

Aha! :) Thx Jaxel!

James
 
Could I use this to replace multiple line breaks with a single line break?

I'm thinking the match pattern would be something like:

\r\n\r\n|\n\n|\r\r

And the replacement would be

\n

Would this work?
 
I would use this:
Code:
$post['message'] = preg_replace('#\n{2,}#', "\n", trim($post['message']));

This would search for instances of 2 or more \n tags and replace it with \n... you could also use \r\n if you needed it, but on my forum \n works better.
 
Top Bottom