Skip to content
WJunction - Webmaster Forum

How to make a text line without wrap ?

Status
Not open for further replies.

mannNmeet

Established Member
496
2011
95
Hello

I want to know how to stop warping a long text line in php
Means we set the value of characters after that it would be like ....\

Example

Before -

I love php but I don't know how to use it exactly.


After -

I love php but I don't know .....


please help me.

Thanks,
mann
 
Last edited:

1 comment

This could be easily achieved with php substr function

Link: http://php.net/manual/en/function.substr.php

Example code to do your task:

PHP:
<?php

$maxlength = 30;

$actualstring = "I love php but I don't know how to use it exactly.";

$outputstring = (strlen($actualstring) > $maxlength) ? substr($actualstring, 0, $maxlength) . "..." : $actualstring;

echo $outputstring;

?>
Specify max words in maxlength var! and check if length exceeds through strlen in ternary operator

The above code will not work if actualstring is small then maxlength! it will only output default data
 
Status
Not open for further replies.

About the author

M
Established Member · Joined
496
Messages
95
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom