|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
substr() not i a midde of some word!
Hello i want to cut a string to show a preview of the news in the frontpage..
but if i substr the first 250 letters, it may end up in a middle of word and i donīt want that? |
|
#2
|
|||
|
|||
|
just appened ... to the end of whatever you substr out. for example
PHP Code:
|
|
#3
|
|||
|
|||
|
this doesnīt work..
You donīt know what iīm talking about... iīm not talking about splicing a "...." at the end of the string... I donīt want to end in a middle of word if that is the 250 letterplace.. i wanīt to get some method to overcome that the preview ends in a middle of some word.. |
|
#4
|
|||
|
|||
|
How about something like this:
<?php define("MAX_LENGTH", 50); $news = "today marks the launch of devscripts.com, a site where developers can find free programming scripts and source code, rate scripts and more!"; $arrNews = explode(" ", $news); $len = 0; $output = ""; for($i = 0; $i < sizeof($arrNews) || $len >= MAX_LENGTH; $i++) { $len += strlen($arrNews[$i]); $output .= $arrNews[$i]; } echo $output; ?> Some code like that shown above would split each word into an array and grab the words until the length of the output string was equal to or just greater than 250... maybe you could work around some code like this? |
|
#5
|
|||
|
|||
|
PHP Code:
That should solve your problem..... PS: Untested but should work....... ![]() |
|
#6
|
|||
|
|||
|
hm yeah jpenn that will work
i was just going for something simple, google style =Dthis is your resu..... heh |
|
#7
|
|||
|
|||
|
I think you donīt know much in php programming...
|
|
#8
|
|||
|
|||
|
lol
sure thing arnorg. try to keep it nice, i didn't make any negative comments about the fact you needed help with this =( |
|
#9
|
|||
|
|||
|
thatīs true
but although tou wrote some crap that maked no sense... with what i was asking about.. |
|
#10
|
|||
|
|||
|
Of course it made sense. Simply adding '...' at the end of the selected phrase, be it in the middle of a word at between words, clearly indicates that there is more to read. That's what the ellipsus means. It's certainly not the BEST solution, but it's an adequate and lazy one
![]() And as I said jpenns' was mucho bettar! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > substr() not i a midde of some word! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|