zohab Posted December 29, 2009 Share Posted December 29, 2009 Hi, I have drop down and I want to break string in drop down. <?php function breakString($string, $delimeter = "<br />\n", $breakAt=15) { $breaks = ceil(strlen($string) / $breakAt); // break every 15 characters $newString = ""; for ($i=0; $i<$breaks; $i++) { $newString .= substr($string, ($i * $breakAt), $breakAt) . $delimeter; } return $newString; } ?> <select name="mydropdown"> <?php $data = array("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","bbbb","cccc","dddd","eeee","ffff","gggg","hhhh","iiii","jjjj"); for($i=0;$i<=sizeof($data);$i++) { ?> <option value="<?php echo $i; ?>"><?php echo breakString($data[$i],"<br/>\n",25) ?></option><?php } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/186580-breaks-long-string-in-drop-down/ Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 You cannot break a string in a select menu as far as I know.. You can however shrink it down and add a ... to the end and have the full string as the value of the option.. Quote Link to comment https://forums.phpfreaks.com/topic/186580-breaks-long-string-in-drop-down/#findComment-985354 Share on other sites More sharing options...
oni-kun Posted December 29, 2009 Share Posted December 29, 2009 Yeah, Simple example being: $var = "Longgggggggggggggggg"; if (strlen($var) > 5) { $var = substr($var, 0, 4).".."; } echo $var; //Long.. Quote Link to comment https://forums.phpfreaks.com/topic/186580-breaks-long-string-in-drop-down/#findComment-985356 Share on other sites More sharing options...
Adam Posted December 29, 2009 Share Posted December 29, 2009 And to add, select options cannot span multiple lines. Quote Link to comment https://forums.phpfreaks.com/topic/186580-breaks-long-string-in-drop-down/#findComment-985458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.