hey guys i have seen this before but have no clue how to do it.
when you insert texte with a titles in a database.when you extract it and put just the titke on a page with very limited space if the title is to long it deforms the page.
i have seen like
tutorial on how.....
limit words
Started by techker, Mar 01 2009 08:38 AM
8 replies to this topic
#1
Posted 01 March 2009 - 08:38 AM
|
|
|
#2
Posted 01 March 2009 - 09:45 AM
What kind of a limit do you have in mind?
#3
Posted 01 March 2009 - 11:04 AM
just like a limit of 10 caracters in the box
#4
Posted 01 March 2009 - 11:07 AM
You can use the maxlength property to limit text input of an input field.
#5
Posted 01 March 2009 - 11:40 AM
what about in an echo?
cause on my page i have an echo(title)
i think the notification on the forums dosnt work all the time..
cause on my page i have an echo(title)
i think the notification on the forums dosnt work all the time..
#6
Posted 01 March 2009 - 12:32 PM
I would do something like this:
usage:
function smarttopic($topic, $max=30, $min=0) {
if ($min == 0) {
$min = $max-10;
}
if (strlen($topic) < $max) {
return $topic; //if string isn't too long, return the whole string
} else {
$part = substr($topic, $min, $max);
$pos = strpos($part, " ");
if ($pos) { // if there is a space between min and max, cut at it
return substr($topic, 0, $min+$pos)."...";
else { // otherwise, cut at mid between min and max
return substr($topic, 0, $min(+($max-$min)/2))."...";
}
}
}
usage:
echo smarttopic("this is a long but spaced topic that will have a good cut", 30, 20);
echoes"this is a long but spaced..."
echo smarttopic("long word topics like intercontinental airlines"), 40);
echoes "long word topics like intercontinen..."
Edited by Orjan, 02 March 2009 - 03:54 AM.
first code line if had an = too little.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#7
Posted 01 March 2009 - 04:58 PM
thx i will try this out!
#8
Posted 02 March 2009 - 03:22 AM
Great work Orjan!
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#9
Posted 02 March 2009 - 03:55 AM
I noticed an error, there was an equal sign (=) lacking on the first row (at the if). edited.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall


Sign In
Create Account


Back to top









