Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 13 Feb 2002, 06:02
TranceCan TranceCan is offline
 
Join Date: Feb 2002
Question Regex on username for chat login

Hello,

We are using the chat hack to integrate IRC chat in our forums. The problem is with usernames that are valid in VB, but not in IRC. What I would like to do is add a piece of code to check usernames and remove invalid characters as they are sent into chat.

ie. [A.O.E.]sNiPeR (that's an example of a REAL username in our forums).

The regex I need (I could never grasp how to write regular expressions) would remove any brackets and convert periods and space to underscores. So, in this example, it would become:

A_O_E_sNiPeR

Or in the case of a space, like: The Dude, would become The_Dude.

Can someone PLEASE give me a code snippet that will do that?

THANKS!!!!!
Reply With Quote
  #2  
Old 13 Feb 2002, 06:22
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
You could use str_replace(). I don't think you'll need the power of regular expressions, so str_replace will give you more speed.

example:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #3  
Old 13 Feb 2002, 06:41
TranceCan TranceCan is offline
 
Join Date: Feb 2002
Originally posted by Mark Hensler
You could use str_replace(). I don't think you'll need the power of regular expressions, so str_replace will give you more speed.

example:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Very close! Didn't work for me though, so I dug in the PHP manual and ended up with this:

$search = array('[', ']', '.', ' ');
$replace = array('', '', '_', '_');

$string = str_replace($search, $replace, $string);

Works like a charm now!! Thanks for your help, got me on the right trail!!
Reply With Quote
  #4  
Old 13 Feb 2002, 19:32
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
sorry...
This is what I wanted to post, but aparently my mind wasn't with me at the time.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I this because you can see the pairs easier.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 09:10.

Layout Options | Width: Wide Color: