Login   Register  
PHP Classes
elePHPant
Icontem

It's a good function but PHP already had a core function that...

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      String Delimiter  >  All threads  >  It's a good function but PHP already had a core function that...  >  (Un) Subscribe thread alerts  
Subject:It's a good function but PHP already had a core function that...
Summary:Package rating comment
Messages:4
Author:Dionei Miodutzki
Date:2011-12-24 15:20:53
Update:2011-12-24 17:03:26
 

Dionei Miodutzki rated this package as follows:

Utility: Bad
Consistency: Sufficient

  1. It's a good function but PHP already had a core function that...   Reply   Report abuse  
Picture of Dionei Miodutzki
Dionei Miodutzki
2011-12-24 15:20:54
It's a good function but PHP already had a core function that can do the same, and better. Take a look at the wordwrap function docs.

  2. Re: It's a good function but PHP already had a core function tha   Reply   Report abuse  
Picture of LampX
LampX
2011-12-24 15:51:39 - In reply to message 1 from Dionei Miodutzki
No no no no no... you didn't get it.
the "wordwrap" function does the "wordwrap" of the win32 controls, returning a paragraph...
THIS CLASS returns a new string limited to certain length, but just until the last "complete" sub-string, avoiding annoying incomplete words at the end of the string. It is useful in forums or mails where you have limited length of text (for some reason)...
Maybe there is a core funtion to do this, but it is NOT wordwrap hehe...
cheers.



  3. Re: It's a good function but PHP already had a core function tha   Reply   Report abuse  
Picture of Dionei Miodutzki
Dionei Miodutzki
2011-12-24 16:36:43 - In reply to message 2 from LampX
Paulo, the only difference is that this class returns only the first line that would be returned by the wordwrap function.

You can simplify it by doing this:

echo strstr(wordwrap(preg_replace('/\s+/', ' ', trim($textstring)), 55, '<*>'), '<*>', true);

  4. Re: It's a good function but PHP already had a core function tha   Reply   Report abuse  
Picture of LampX
LampX
2011-12-24 17:03:26 - In reply to message 3 from Dionei Miodutzki
wordwrap function looks like a mess if you use it directly, so the idea of this friend was doing it as simple as this:

echo $delimiter->limit(55,$textstring);

versus:

echo strstr(wordwrap(preg_replace('/\s+/', ' ', trim($textstring)), 55, '<*>'), '<*>', true);

Anyways i agree with you that the class code can be "simplified" using the wordwrap function, i think this class has too much code... but the idea is good.