parsing posts - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

parsing posts

FirestormFirestorm Posts: 162Member
Hi I'm looking for a way to parse text "dynamically" for a kind of BBcode.
In my guestbook you can specify the text color like on this board and then something like
[code]
[color=#HEXHEX]
[/code] appears. Now I need a regex or something to look for
[code]
[color= ]
[/code] and replace it with
[code]

[/code] using the #HEXHEX value. Has anyone an idea how to do such a thing?

Mainly my problem is not finding the [color=#0-1a-fA-f] but to convert it to
[code]

[/code]
________________________________
[red]http://www.againsttcpa.com[/red]
[blue]Don't give big brother a chance![/blue]

Comments

  • JonathanJonathan Posts: 2,914Member
    Hi,

    In PHP you have the preg_replace function, which I believe will take similar synatx to that we use to pattern match in Perl.

    You need to look for:-

    [code][color=(#HEXHEX)](.*?)[/color][/code]

    And replace it with this:-

    [code]$2[/code]

    So my guess would be to do something like this:-

    [code]$var = preg_replace("[color=(#HEXHEX)](.*?)[/color]",
    "$2", $var, -1);[/code]

    Perl is much nicer here, you would just do:-

    [code]$var =~ s/[color=(#HEXHEX)](.*?)[/color]/$2/g;[/code]

    Hope this helps,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • FirestormFirestorm Posts: 162Member
    Sorry that I'm that late. I had a lot of mess aournd so even could not test your code! Actually I'm using a lame str_replace to replace the BBCode with < span style="color: > - you know what I mean.

    anyway thanks a lot for your reply - I WILL test it!
    : Hi,
    :
    : In PHP you have the preg_replace function, which I believe will take similar synatx to that we use to pattern match in Perl.
    :
    : You need to look for:-
    :
    : [code][color=(#HEXHEX)](.*?)[/color][/code]
    :
    : And replace it with this:-
    :
    : [code]$2[/code]
    :
    : So my guess would be to do something like this:-
    :
    : [code]$var = preg_replace("[color=(#HEXHEX)](.*?)[/color]",
    : "$2", $var, -1);[/code]
    :
    : Perl is much nicer here, you would just do:-
    :
    : [code]$var =~ s/[color=(#HEXHEX)](.*?)[/color]/$2/g;[/code]
    :
    : Hope this helps,
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    ________________________________
    [red]http://www.againsttcpa.com[/red]
    [blue]Don't give big brother a chance![/blue]

Sign In or Register to comment.