Page 1 of 1

function to truncate a string to n chars

Posted: Wed Aug 30, 2006 2:38 am
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;

}

Posted: Wed Aug 30, 2006 3:11 am
by CoderGoblin
What's your definition of php a inbuilt function ?

Posted: Wed Aug 30, 2006 3:27 am
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?