Tasos
October 18, 2015, 12:38pm
1
Hello,
I need to subtract characters greater than 25 and add dots.
For example:
National and Local Weather Forecast
±----------------------35----------------------+ 35 Characters
To National and Local Weathe… which is 25 characters.
And if less than 25 don’t add dots after the last character.
National and Local
±---------18----------+ 18 Characters
What i already have.
while($row = mysql_fetch_assoc($getquery))
{
echo '<h2>'. substr($row['msg'], 0, 25).'..</h2>';
}
Which i don’t know how to fix that, because the dots are everywhere after the last character.
Thanks in advance
Try something like this:
‘’’
$msg = “this is a test to see if it works”;
If (strlen($msg) > 25 ) {
$msg = substr( $msg, 0, 25) . ‘…’;
}
echo $msg;
‘’’
[ot] it’s hard work typing script on a mobile
[/ot]
1 Like
Tasos
October 18, 2015, 3:23pm
3
Thank you verry much it solved my problem.
Off Topic:
A year ago a client call me to fix his website ( i am not an expert at programming ) but i can solve allot and work almost always with ready made scripts, but i was traveling so i had to work trough my phone it took me almost 2 hours to fix the problem.
On the PC it would take max 15 to 30 min
1 Like
You may want to consider putting strrpos in there somewhere eg.
one often makes false assumptions
system
Closed
January 17, 2016, 10:48pm
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.