Shortening if-statements of displaying errors Is it possible to shorten this piece of PHP code?

Honestly, I think it does not look clean but like a mess.

if(Input::exists() &amp;&amp; $token) {
    if($validation-&gt;error('firstname') &amp;&amp; $validation-&gt;error('lastname')) {
        echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ You did not enter your name.&lt;/div&gt;', "\n";
    } else if($validation-&gt;error('firstname')) {
        echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ You did not enter your first name&lt;/div&gt;', "\n";
    } else if($validation-&gt;error('lastname')) {
        echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ You did not enter your last name.&lt;/div&gt;', "\n";
    }
}
if(!Input::exists()) {
        echo str_repeat(' ', 20), '&lt;div class="addition"&gt;↳ We will address you by this name.&lt;/div&gt;', "\n";
}

if(Input::exists() &amp;&amp; $token) {
    if($validation-&gt;error('emailConfirm') == 'match') {
        echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ The email address you entered does not match.&lt;/div&gt;', "\n";
    } else if($validation-&gt;error('emailConfirm') == 'type') {
        echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ You did not re-enter a valid email address.&lt;/div&gt;', "\n";
    } else if($validation-&gt;error('emailConfirm')) {
        echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ You did not re-enter your email to confirm.&lt;/div&gt;', "\n";
    }
}else if(!Input::exists()) {
        echo str_repeat(' ', 20), '&lt;div class="addition"&gt;↳ Re-enter your email to make sure it\'s correct.&lt;/div&gt;', "\n";
    }
You are repeating the same code:

echo str_repeat(' ', 20), '&lt;div class="addition error"&gt;↳ You did not enter your name.&lt;/div&gt;', "\n";


Replace it with a function which will do the job:

function message($content, $class = ''){
    return str_repeat(' ', 20) . '&lt;div' . (($class) ? " class='$class'" : '') . "&gt;$content&lt;/div&gt;\n";
}


You are using construction:

if () {} else if() {}


This is the same as: 

if () {} else { if() {} }


I guess, that it is not what you want to use, the correct construction should be:

if () {} elseif() {} 


The code itself can be rewritten like this:

function message($content, $class = ''){
    return str_repeat(' ', 20) . '&lt;div' . (($class) ? " class='$class'" : '') . "&gt;$content&lt;/div&gt;\n";
}

if (!Input::exists()){
    echo message('We will address you by this name.', 'addition');
    echo message('Re-enter your email to make sure it\'s correct.', 'addition');
} elseif (Input::exists() &amp;&amp; $token) {
    if($validation-&gt;error('firstname') &amp;&amp; $validation-&gt;error('lastname')) {
        echo message('You did not enter your name.', 'addition error');
    } elseif($validation-&gt;error('firstname')) {
        echo message('You did not enter your first name', 'addition error');
    } else {
        echo message('You did not enter your last name.', 'addition error');
    }

    if($validation-&gt;error('emailConfirm') == 'match') {
        echo message('The email address you entered does not match.', 'addition error');
    } elseif($validation-&gt;error('emailConfirm') == 'type') {
        echo message('You did not re-enter a valid email address.', 'addition error');
    } else {
        echo message('You did not re-enter your email to confirm', 'addition error');
    }
}