Results 1 to 6 of 6

Thread: Most likely a preg_replace question?

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Question Most likely a preg_replace question?

    It's hard to explain so i'll provide an example:

    If someone types "/me says hello" in a textbox, how can i parse this (using preg_replace) so that it will be displayed as:

    <font color="red">* da_silvy says hello</font>

    In a shoutbox?

    Can someone please tell me the code for this

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    well you would have to get the /me to be exchanged with the user name.

    preg_replace('/(\/me)(.*)/U','$username //2, $string);

  3. #3

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    didn't seem to work

    Also, i want it to work for that line, so that when a /me appears on the start of the line, it will add a tag at the front and a tag at the end of the line..

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Most likely a preg_replace question?

    Originally posted by da_silvy
    It's hard to explain so i'll provide an example:

    If someone types "/me says hello" in a textbox, how can i parse this (using preg_replace) so that it will be displayed as:

    <font color="red">* da_silvy says hello</font>

    In a shoutbox?

    Can someone please tell me the code for this
    Code:
    $string = preg_replace("/\me(*.)/\n", '<font color="read">' . $username . '\\1</font>', $string);
    I'm not sure how to fit the newline in there, though.

    If I you haven't gotten a proven answer by the time I get home from school, I'll give it a shot.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by da_silvy
    didn't seem to work

    Also, i want it to work for that line, so that when a /me appears on the start of the line, it will add a tag at the front and a tag at the end of the line..
    sorry fogot to add that.

    preg_replace('/(\/me)(.*)/U','<font color=red>'.$username.' //2</font>, $string);

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Error Correction on phpman's code:

    PHP Code:
    preg_replace('/(\/me)(.*)/U','<font color=red>'.$username.' //2</font>'$string); 
    (forgot a ')
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width