Limit Output

Hello, I am new to php and trying to understand it. I want to know if someone could tell me how to limit the output of an echo $value. Below is the code and I need to limit the output to about 45 characters and if possible add … to the end to show there is more text.

[php]<?php if($value[‘locationbold’] == ‘1’)
echo “”.$value[‘location’]."&nbsp";
else
echo $value[‘location’]."&nbsp";?>[/php]

I need to limit the output to about 45 characters and if possible add ... to the end to show there is more text.

and you mean? the uputput should be only 45 characters long if is longer than 45 add it the end?

should be only 45 characters long

you can check the length of a string with the php function strlen()

eg:
[php]

<?php if(strlen($value['locationbold']) == 45){ echo "".$value['locationbold']."&nbsp"; }else{ echo $value['location']."&nbsp"; } ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service