function to truncate a string to n chars
Posted: Wed Aug 30, 2006 2:38 am
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;
}
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;
}