Created
August 13, 2014 19:28
-
-
Save juniorb2ss/eda182e5394df521604d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Template { | |
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; | |
} | |
} | |
$template = new Template; | |
$file_include = 'menu aqui'; // pegando o arquivo menu file_content etc... | |
$template->SetKeywords('hello_world', 'hello_world'); | |
$template->SetKeywords('menu', $file_include); | |
$file = '{$hello_world} template // {$menu}'; | |
var_dump($template->GetReplaceKeywordCount($file)); | |
$file = $template->ReplaceKeywords($file); | |
echo $file; // return file | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment