this should be very simple question, but i cant get it working for some reason, my framework is PHALCON
$string='GuGuSy';
i want this to be replaced as
$output = 'AAB';
so I coded it as:
public function graha($planet)
{
if(strpos($planet,'Sy')!==false){
$planet = preg_replace("/Sy/",'B',$planet);
}
if(strpos($planet,'Gu')!==false){
$planet = preg_replace("/Gu/",'A',$planet);
//str_replace("Gu",'A',$planet);
}
return $planet;
}
but output I get is not correct, why?
My output is for the string is "A" only why ?
$string='GuGuSy';
function graha($planet)
{
$a='';
if(strpos($planet,'Sy')!==false){
$a= $planet = preg_replace("/Sy/",'B',$planet); // $planet=GuGuB
}
if(strpos($planet,'Gu')!==false){
$a= preg_replace("/Gu/",'A',$planet);
}
return $a;
}
echo graha($string);
Issue was related to the Phalcon framework it self
when you return values it seems to use the last returned value only in VOLT templating system. So what you have to do it echo $planet in the function to get the correct value displayed in the phalcon-volt system.