Search code examples
phpsubstr

Cut letters from behind with substr


<?php echo $entry->field('logo')->generate(); ?>

This gives me the path of my images, but I want to cut the last 3 letters from the back(the suffix).

The normal function is:

<?php
rest = substr("Test", 0, -1);
?>

But I don't get an output with this:

<?php
$rest = substr($entry->field('logo')->generate(), 0, -1); 
?>

Solution

  • You have to take the value in a variable

    $var = $entry->field('logo')->generate();
    

    Then you put the substr function on the variable

    $rest = substr($var, 0, -1);