Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2005, 05:29 PM   PM User | #1
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
FUNCTION(S): Chat Actions

Well since I just got this into my ShoutBox I thought I'd share the ending result for people that want to make actions like in phpMyChat and IRC and such for their PHP script.

PHP Code:
<?php

function ActionParser($string$username) {
  
$string preg_replace('/^\/me/''<b>'.$username.'</b>'$string);
  return 
$string;
}

echo 
ActionParser("/me bashes you over the head. /me""Element");  


?>
That will output:
Quote:
Element bashes you over the head. /me
Notice how it ignores the second /me? Thats good. That was a problem with my original version. Another way to implement these codes with others is like so

PHP Code:
<?php

function ActionParser($string$username) {
  if(isset(
$string) || isset($username)) {
    
$string ActionMe($string$username);
    
$string ActionHe($string$username);
    
$string ActionShe($string$username);
    
$string ActionIt($string$username);
    return 
$string;
  } 
}

function 
ActionMe($string$username) {
  
$string preg_replace('/^\/me/''<b>'.$username.'</b>'$string);
  return 
$string;
}

function 
ActionHe($string$username) {
  
$string preg_replace('/^\/he/''<b>'.$username.'</b>'$string);
  return 
$string;
}

function 
ActionShe($string$username) {
  
$string preg_replace('/^\/she/''<b>'.$username.'</b>'$string);
  return 
$string;
}

function 
ActionIt($string$username) {
  
$string preg_replace('/^\/it/''<b>'.$username.'</b>'$string);
  return 
$string;
}

echo 
ActionParser("/it is not a boy or girl! o.O""RockThing");

?>
And of course you can use the same method to make other actions, like viewing profiles and such.
Element is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:09 AM.


Advertisement
Log in to turn off these ads.