• 0

[PHP][CLASS] Extruding values from an return


Question

Hello There!

I have got an awful problem. The Class that I created, is working, but I want to do more with this. In the SERVER_DESCRIPTION I want to have multiple items for my website, like the member_id, name of de DJ and if it is a DJ or a Show for the kind of banner.

SERVER_DESCRIPTION is set on "Name=DJName,ID=1,Kind=DJ". But I can not figure out a way to get the values extruded of the SERVER_DESCRIPTION.

Can anyone help me with this one?

   function getKind() {
      return($this->_values[$this->_indexes["SERVER_DESCRIPTION"][0]]["value"]);
   }

   function getName() {
      return($this->_values[$this->_indexes["SERVER_DESCRIPTION"][0]]["value"]);
   }

   function getID() {
      return($this->_values[$this->_indexes["SERVER_DESCRIPTION"][0]]["value"]);
   }

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

<?php
$parser = new ServerDescriptionParser('Name=DJName,ID=1,Kind=DJ');
echo $parser->getId();	#1
echo $parser->getName(); #DJName
echo $parser->getKind(); #DJ
?>

<?php
class ServerDescriptionParser
{
 protected
	$_pairs = array();

 public function __construct($description){
	parse_str(
 	str_replace(
 	',',
 	'&',
 	$description
 	),
 	$this->_pairs
	);
 }

 public function getName(){
	return $this->getValue('Name');
 }

 public function getId(){
	return $this->getValue('ID');
 }

 public function getKind(){
	return $this->getValue('Kind');
 }

 protected function getValue($key){
	return array_key_exists($key, $this->_pairs) ? $this->_pairs[$key] : null ;
 }
}
?>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.