Textreplace, need some help please

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

    Textreplace, need some help please

    Hi,

    I use phpBB-forum and I want to spice it up with a little feature.

    Users should be able to put a statement like "[XXYYY]" into their posts
    which I would like to replace with a link after they sent their post (it
    will become a link to a db-application later).

    I ask this question because I am just a PHP-user and no developer, but I
    guess I am able to paste some code into the phpBB-forum code ;-)

    So which informations I can give you:

    [XXYYY] needs to be replaced

    XX is alsways 2 chars long
    YYY is 1-3 chars long

    e.g. [WC123] or [WM1]

    Each Statement like that should be replaced with a link of the form:

    <A HREF="targetlin k?varA=XX&varB= YYY">[XXYYY]</A>

    Thanks in advance,
    Kay
  • John Dunlop

    #2
    Re: Textreplace, need some help please

    Kay Molkenthin wrote:
    [color=blue]
    > [XXYYY] needs to be replaced
    >
    > XX is alsways 2 chars long
    > YYY is 1-3 chars long
    >
    > e.g. [WC123] or [WM1][/color]

    Is that "XX is always two [uppercase] alphabetic characters long" and
    "YYY is always one to three decimal digits long"?
    [color=blue]
    > Each Statement like that should be replaced with a link of the form:
    >
    > <A HREF="targetlin k?varA=XX&varB= YYY">[XXYYY]</A>[/color]

    Going by what you said, not what I assumed, example A:

    $string = preg_replace(
    '`\[(.{2})([^]]{1,3})\]`s',
    '<A HREF="targetlin k?varA=$1&amp;v arB=$2">$0</A>',
    $string)

    Going by what I assumed, example B:

    $string = preg_replace(
    '`\[([A-Z]{2})(\d{1,3})\]`',
    '<A HREF="targetlin k?varA=$1&amp;v arB=$2">$0</A>',
    $string)

    Notice in HTML4.01 that there is no entity reference named "varB", so
    I've taken the liberty of substituting the entity reference &amp; for
    the literal ampersand you had. Validation would've spotted that for
    you though.

    Moreover, if you use example A, you run the risk of letting forbidden
    characters creep into the query component. You'd need to ensure
    they're properly encoded.

    HTH.

    --
    Jock

    Comment

    • Kay Molkenthin

      #3
      Re: Textreplace, need some help please

      > Is that "XX is always two [uppercase] alphabetic characters long" and[color=blue]
      > "YYY is always one to three decimal digits long"?[/color]

      Yes.

      Thanks for your support, I will test it and give you a feedback asap.

      Kay

      Comment

      • Kay Molkenthin

        #4
        Re: Textreplace, need some help please

        On Wed, 3 Mar 2004 22:51:16 -0000, John Dunlop
        <john+usenet@jo hndunlop.info> wrote:
        [color=blue]
        > $string = preg_replace(
        > '`\[([A-Z]{2})(\d{1,3})\]`',
        > '<A HREF="targetlin k?varA=$1&amp;v arB=$2">$0</A>',
        > $string)[/color]

        You saved my life, thanks!!!

        Comment

        Working...