I have situation, where I have to echo certain length for several variables at various locations.
I know in bash we can use echo ${variable:0:20} to achieve this, without rewriting or refining the variable.
for example in php I want to be able to do this.
$string1 = "I am looking for a way to only echo the first 20 characters from a string variable"; echo $string:0:20; I know it is dead simple to redefine my variable in php like this and echo it.
$small = substr($big, 0, 20); echo $small; But I have to use the same variable at some many location and each location I have to echo different length, so it is not feasible to use the above method. Is there is something else I am missing that I could use?