FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Remove Text?





Diablosblizz
Hey, I am making a staff page for my radio site. I am making DJ profiles and because the DJ might or might not have the word DJ on the DJ name it can change.

What I am looking for was a PHP (or Javascript) that removes the word DJ from the variable. I have googled, and I sort of found this:

Code:
<?php
function cleanData($variable, $type, $theDefinedValue = "", $theNotDefinedValue = "") {

 $variable = (!get_magic_quotes_gpc()) ? addslashes($variable) : $variable;

 switch ($type) {
   case "text":
     $variable = ($variable != "") ? $variable : "NULL";
     break;   
   case "long":
   case "int":
     $variable = ($variable != "") ? intval($variable) : "NULL";
     break;
   case "double":
     $variable = ($variable != "") ? doubleval($variable) : "NULL";
     break;
   case "date":
     $variable = ($variable != "") ? $variable : "NULL";
     break;
   case "defined":
     $variable = ($variable != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $variable;
}

$user = $_GET['username'];
$dj = cleanData($user, "DJ");
echo "$dj";
?>


That doesn't remove the DJ part. Does anybody know how I can do this?

Many thanks!
PseudoKnight
I know this is not what you asked, but why not just add DJ in the database as needed? It seems like a content oriented issue, not a template issue.
AftershockVibe
The function you're (probably) looking for will be str_replace() like this:

Code:
$name = str_replace("DJ", "", $name);


You'll have to be careful that "DJ" doesn't occur anywhere else in a name though. I can't think of any good examples of where that might occur though, unless you have a friend who happens to be called "Adjective Jones" and always spell his name in CAPS.

Even then you can add spaces to either side of the "DJ" search string to help avoid that.
blueray
or you may have the username with a format like
USERNAME:1 or
USERNAME:0

as PseudoKnight said

when loading the username, it could be parsered to know whether it should
includes the TITLE DJ or not.

Wish this help.
Agent ME
This would be annoying if you had a DJ named DJ and he couldn't figure out why it wouldn't show his name.

When you add the people to the database just make a note not to include any title.
Related topics
10 photoshop effect tutorials
users online, using php and text file
NotePad Replacements
Php as text and short urls.
Great Photoshop Tutorials
PHP include code problem
[PHP] Calling dynamic pictures
fdas
Never Mind Problem Resolved
Favorite CMS.
Slapping a WaterMark Automatically.
$400 frih FOR LOGO
Text - Image
Free Rich Text Editor
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.