Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.