0

I'm beginner and I have a question. I would like that if my text is more than 5 characters, that it writes 5 characters + ... . It's for shortening a name in navbar if its too long, it causes bugs in my nav.

Here's an example of desired result:
My text: TheTest
output: TheTe...

I think I could do this with strlen() but have no idea how to do this. Maybe with an overflow ?
I tried to do it with text-overflow: ellipsis; but it didn't work either Can you help me please ?

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
One 4046
  • 53
  • 1
  • 7
  • You can watch this tutorial https://www.youtube.com/watch?v=n_yK6KFxNww @BaguetteV1.0 – Pie May 28 '19 at 15:31

1 Answers1

1

just check the length to see if its more than 5 character or not

$mesage="This is text String";

if(strlen($mesage)>5){

    echo substr($mesage,0,5)."...";
}
else{

    echo $mesage;
}

More infos about strlen(): http://www.php.net/manual/de/function.strlen.php
substr(): https://www.php.net/manual/en/function.substr.php

Mohit Kumar
  • 952
  • 2
  • 7
  • 18