3v4l.org

run code in 300+ PHP versions simultaneously
<?php $output = "hello Mary."; $suffix = "added text to crop on condition"; $output .=$suffix; //append suffix to output $condition = true; // change to false to simulate case where no cropping is needed if($condition){ $suffix_len = strlen($suffix); //length of the suffix $output_len = strlen($output); //length of the whole output (including suffix) //if suffix is found at the end of the output if(substr($output,$output_len-$suffix_len) == $suffix){ $output = substr($output,0,$output_len-$suffix_len); //crop } } echo $output;
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
hello Mary.

preferences:
171.27 ms | 404 KiB | 290 Q