[ create a new paste ] login | about

Link: http://codepad.org/2C8fP670    [ raw code | output | fork ]

PHP, pasted on Sep 13:
<?php
class string  {
	private $words;

	public function SetKeywords($Setkeyword, $Setvalue){
		if(gettype($this->words) != 'array'){
			$this->words = array();
		}
		$array = array($Setkeyword => $Setvalue);
		$this->words = array_merge($array,$this->words);
	}

	public function ReplaceKeywords($maskContent) {
		if($this->words){
			if(!$maskContent || strlen($maskContent) == 0)
				return $maskContent;
			
			foreach($this->words as $keyword=>$value)
			{
				$keyword = '{'.$keyword.'}';
				$maskContent = str_replace($keyword, $value, $maskContent);
			}
			return $maskContent;
		}
		else
		{ 
		return false; 
		}
	}

	public function GetReplaceKeywordCount($maskContent){
			if(!$maskContent || strlen($maskContent) == 0)
				return $maskContent;
			$count = array();
			foreach($this->words as $keyword=>$value){
				$searchWord = '{'.$keyword.'}';
				$wordCount = substr_count($maskContent, $searchWord);
				if($wordCount > 0)
					$count[$keyword] = $wordCount;
			}
			return $count;
	}
}


$string = new string;




$string->SetKeywords('DB_TYPE', 'MySQL');
$string->SetKeywords('DB_USER', 'root');


$arrayConfig = "$configs = [
	'DB_TYPE' => '{DB_TYPE}',
    'DB_USER' => '{DB_USER}'
]";



$string = $string->ReplaceKeywords($arrayConfig);

echo $string; // return file


Output:
1
2
3
4
 = [
	'DB_TYPE' => 'MySQL',
    'DB_USER' => 'root'
]


Create a new paste based on this one


Comments: