Error returning Stringstr

Asked

Viewed 585 times

0

I have the following function in php it returns me a page string so that I can do if and Else with the returned information, but there is an error: Parse error: syntax error, Unexpected '=' in /Storage/ssd3/854/1950854/public_html/config.php on line 22

how can I fix it ? (apparently the line with the error is the name but I don’t know how to fix 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;

  • Change to $name

1 answer

2


In this case it is a syntax error, its variable name is missing the dollar $, which is mandatory for variables as per PHP language definition. Therefore including the cipher 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.