Search code examples
phpcssvariablesstylesheetif-statement

Change Stylesheet via If in php


At the moment i'm trying to use a stylesheet which i get through a if. but it doesn't do anything.

here is my code at the moment. the variable $stylesheet will be variable but while testing i've setted it to normal

<?php
$stylesheet = 'normal'
if ($stylesheet = 'small')
    {
    $style = './sitestyle/stylesheetsmall.css';
    }

if ($stylesheet = 'big')
    {
    $style = './sitestyle/stylesheetbig.css';
    }
  else
    {
    $style = './sitestyle/stylesheet.css';
    }

echo '<link rel="stylesheet" type="text/css" href="$style">';
?>

Thanks for your answers.


Solution

  • Ok, so as the others have said, = is assignation, == is comparision.

    But your problem could be simplified by using a switch statement:

    $stylesheet =  'normal';
    switch($stylesheet) {
        case 'small':
            $style = './sitestyle/stylesheetsmall.css';
            break;
        case 'big':
            $style = './sitestyle/stylesheetbig.css';
            break;
        default:
            $style = './sitestyle/stylesheet.css';
            break;
    }
    echo '<link rel="stylesheet" type="text/css" href="'.$style.'">';