if / else in return tag

I'm quite new to PHP, so this is probably a stupid question.

I have an if/else that I need to use in a return tag, but it doesn't work. How should I structure this?

This is the tag:

return '… <div class="read"><a class="read-more hvr-icon-forward" href="'. get_permalink($post->ID) . '">' . "CODE HERE" . '</a></div>';

This is what I need to output in "CODE HERE"

$status = of_get_option('read_more');
if (empty($status)) {
    echo 'Sorry, the page does not exist.';
} else {
    _e($status);
}

https://jsfiddle.net/33nv1xpa/1/

Do I get it right, you have a structure like

return *SOME_STRING* SOME CODE WITH ";" *SOME_STRING*

?

I would highly recommend, to create a string var containing the text you want to return and finally only return that string.

$echoCode   = result from CODE HERE
$returnText = "<div>blalba</div>" . $echoCode . "<div>blabla</div>";

return $returnText;

You can do it by using the ternary operator, and putting the variable assignment in parenthenses.

return "...". (($status = get_option('status')) ? $status : _e()) ."...";

Otherways, I suggest to put this functionality in a function, or at least in a plain variable. Coding like this makes the whole thing unreadable.

Also, you're trying to run a wordpess function in an online parser which will undeniably miss these features!

Well you can use the Php eval function (http://php.net/manual/en/function.eval.php). It evaluates a string as Php code. So you can assign the result of eval to a variable called $code_here:

$code_here = "$status = of_get_option('read_more');
if (empty($status)) {
    echo 'Sorry, the page does not exist.';
} else {
    _e($status);
}";

$code_here = eval($code_here);