Please help me with PREG_MATCH

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krakatioison

    #1

    Please help me with PREG_MATCH

    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:129beec63 7]
    and ends with: [/quote:129beec63 7]

    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



  • Pjotr Wedersteers

    #2
    Re: Please help me with PREG_MATCH

    Krakatioison wrote:[color=blue]
    > 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:129beec63 7]
    > and ends with: [/quote:129beec63 7]
    >
    > 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[/color]

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


    Comment

    • Krakatioison

      #3
      Re: Please help me with PREG_MATCH

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




      "Pjotr Wedersteers" <pjotr@wederste ers.com> wrote in message
      news:417e4f9c$0 $78772$e4fe514c @news.xs4all.nl ...[color=blue]
      > Krakatioison wrote:[color=green]
      >> 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:129beec63 7]
      >> and ends with: [/quote:129beec63 7]
      >>
      >> 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[/color]
      >
      > Do you want to echo the literal text: [quote etc] or what's between the
      > quote tags ?
      >[/color]


      Comment

      • Pedro Graca

        #4
        Re: Please help me with PREG_MATCH

        Krakatioison wrote:[color=blue]
        > 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:129beec63 7]
        > and ends with: [/quote:129beec63 7][/color]

        I assumed the number is a hexadecimal number.
        [color=blue]
        > Number after "[quote:" is always different and changing its length.[/color]

        <?php
        $text = 'before [quote:1abc08f] middle [/quote:1abc08f] after';

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

        echo $text, "\n";
        echo $text2, "\n";
        ?>
        [color=blue]
        > I need to parse this and display it using different color.[/color]

        Replace the "***" with whatever you prefer.
        [color=blue]
        > Just so, when I display the text, people could figure out where the
        > quotation starts and ends.[/color]

        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. |

        Comment

        Working...