function to truncate a string to n chars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sathish.hc
Forum Newbie
Posts: 15
Joined: Tue May 23, 2006 2:55 am

function to truncate a string to n chars

Post by sathish.hc »

1. write a php function to truncate a string to $n chars without using php inbuilt function.

The string may have <b> </b> tags also. If after truncation a word is cut, then it should be removed from outcome.

Also the output should be appended with </b> if there is a missing </b> tag as a result of truncation. No other tag needs to be handled.

// function declaration

function truncate_str ($str, $n) {

….

return $result;

}
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

What's your definition of php a inbuilt function ?
phpfanatico
Forum Newbie
Posts: 1
Joined: Wed Aug 30, 2006 3:18 am

Post by phpfanatico »

I supose you mean to don't use substr or something similar, it looks like php programming homework and you have to create the substr function by yourself, isn't it?
Post Reply