...

View Full Version : FUNCTION(S): Chat Actions



Element
12-08-2005, 05:29 PM
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

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:

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

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum