By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

Please help me with PREG_MATCH

P: n/a
Hi all,

I need a help to write a simple preg_match.
Imagine, I've got like 5kb of text where one part of the text always

starts with: [quote:129beec637]
and ends with: [/quote:129beec637]

Number after "[quote:" is always different and changing its length.

I need to parse this and display it using different color.
Just so, when I display the text, people could figure out where the
quotation starts and ends.

Could someone please help me with it?
Thanks a lot. Every help is very appreciated and helps me a lot.

Joe

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Krakatioison wrote:
Hi all,

I need a help to write a simple preg_match.
Imagine, I've got like 5kb of text where one part of the text always

starts with: [quote:129beec637]
and ends with: [/quote:129beec637]

Number after "[quote:" is always different and changing its length.

I need to parse this and display it using different color.
Just so, when I display the text, people could figure out where the
quotation starts and ends.

Could someone please help me with it?
Thanks a lot. Every help is very appreciated and helps me a lot.

Joe


Do you want to echo the literal text: [quote etc] or what's between the
quote tags ?
Jul 17 '05 #2

P: n/a
Hi Pjotr,
I need to echo only the original text between "quote:"
Thanks for trying to help me.
Joe


"Pjotr Wedersteers" <pj***@wedersteers.com> wrote in message
news:41***********************@news.xs4all.nl...
Krakatioison wrote:
Hi all,

I need a help to write a simple preg_match.
Imagine, I've got like 5kb of text where one part of the text always

starts with: [quote:129beec637]
and ends with: [/quote:129beec637]

Number after "[quote:" is always different and changing its length.

I need to parse this and display it using different color.
Just so, when I display the text, people could figure out where the
quotation starts and ends.

Could someone please help me with it?
Thanks a lot. Every help is very appreciated and helps me a lot.

Joe


Do you want to echo the literal text: [quote etc] or what's between the
quote tags ?

Jul 17 '05 #3

P: n/a
Krakatioison wrote:
I need a help to write a simple preg_match.
Imagine, I've got like 5kb of text where one part of the text always

starts with: [quote:129beec637]
and ends with: [/quote:129beec637]
I assumed the number is a hexadecimal number.
Number after "[quote:" is always different and changing its length.
<?php
$text = 'before [quote:1abc08f] middle [/quote:1abc08f] after';

$rx = '/\[quote:([0-9a-fA-f]+)\](.*)\[\/quote:\1\]/';
$text2 = preg_replace($rx, '***\2***', $text);

echo $text, "\n";
echo $text2, "\n";
?>
I need to parse this and display it using different color.
Replace the "***" with whatever you prefer.
Just so, when I display the text, people could figure out where the
quotation starts and ends.


Happy Coding :-)
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.