Error returning StringStr

0

I have the following function in php it returns me a string from the page so I can do if and else with the returned information, however an error occurs: Parse error: syntax error, unexpected '=' in / storage / ssd3 / 854/1950854 / public_html / config.php on line 22

How can I resolve this? (apparently the line with the error is the name but I do not know how to solve it)

function GetStr($string, $start, $end){

$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}

name = "sair";
$valor = GetStr($resultado, 'name='",");

echo $valor;
    
asked by anonymous 31.08.2017 / 03:08

1 answer

2

In this case it is a syntax error, its name variable is without the $ , which is mandatory for the variables as defined by the PHP language. So including the ciphode should work:

function GetStr($string, $start, $end){

$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}

$name = "sair";
$valor = GetStr($resultado, 'name='",");

echo $valor;
    
31.08.2017 / 18:02