<?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;