Tristan Šneider
Tristan Šneider

Reputation: 91

function title($_GET["page"]) always returning empty string

This doesn't seem to work correctly for me, it always returns an empty string. I could not find the error that I made.

function title($page){
    $i=0;
    $title="";
    foreach ($page as $c){
        if ($i===0){
            ucfirst($c);
        }
        if ($c=="_"){
            $c=" ";
        }
        $i++;
        array_push($title,$c);
    }
    return $title;
}

Upvotes: 0

Views: 63

Answers (1)

towr
towr

Reputation: 4167

Try

function title($page)
{
  return ucfirst(str_replace('_', ' ', $page));
}

Upvotes: 2

Related Questions