I need to limit this string to max 320 characters but also make it truncate cleanly if it is going to overrun e.g  I want  Testing Item 1 | Testing Item 2 | Testing Item 3   Instead of  Testing Item 1 | Testing Item 2 | Testing Item 3 | Tes   Currently I have this function:  /**      * First filter out any empty values, strip any tags, then join each array item with a pipe | and limit it to 320 characters.      * @param $array      * @return string      */     public function limitStripAndJoin($array) {         // Removes any empty strings from the array e.g if there's no caption on an image, we want to remove the empty string         $filteredArray = array_filter($array, 'strlen');          return strip_tags(substr(join(" | ", $filteredArray), 0, 320));     }   I just need to know how stop going to the next item if it will overrun?
50683
I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage.  The original block of text can be a lengthy article or a short sentence or two; but for this widget I can't display more than, say, 200 characters.  I could use substr() to chop off the text at 200 chars, but the result would be cutting off in the middle of words-- what I really want is to chop the text at the end of the last word before 200 chars.
54729
I'm looking for a way to convert a preprocessor token to a string.  Specifically, I've somewhere got:  #define MAX_LEN 16   and I want to use it to prevent buffer overrun:  char val[MAX_LEN+1]; // room for \0 sscanf(buf, "%"MAX_LEN"s", val);   I'm open to other ways to accomplish the same thing, but standard library only.
9942
Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?  I thought that setting it to null would do it, but apparently it does not work.
70874
Do you know any good tools for nicely formatting messy php code? Preferably a script for Aptana/Eclipse, but a standalone tool will do too.
114354
When manually generating a JSON object or array, it's often easier to leave a trailing comma on the last item in the object or array.  For example, code to output from an array of strings might look like (in a C++ like pseudocode):  s.append("["); for (i = 0; i &lt; 5; ++i) {     s.appendF("\"%d\",", i); } s.append("]");   giving you a string like  [0,1,2,3,4,5,]   Is this allowed?
23579
It's probably beginner question but I'm going through documentation for longer time already and I can't find any solution. I thought I could use implode for each dimension and then put those strings back together with str_split to make new simple array. However I never know if the join pattern isn't also in values and so after doing str_split my original values could break.  Is there something like combine($array1, $array2) for arrays inside of multi-dimensional array?
92527
I'm parsing simple (no sections) INI file in PowerShell. Here code I've came up with, is there any way to simplify it?  convertfrom-stringdata -StringData ( `   get-content .\deploy.ini `   | foreach-object `     -Begin { $total = "" }  `     { $total += "`n" + $_.ToString() } `     -End { $total } ` ).Replace("\", "\\")
121328
We have a database with a large amount of data stored in a field of type varbinary(max). At some point we can purge that data for most rows, but not all. Our plan is to make that field nullable, and simply null out the data when it is no longer needed. Once we do that we would like to reduce the size of the DB. What is the best way to accomplish this?   If there isn't a good way to reclaim space with the current setup, one idea I have is to move that data field to a separate table with just two columns: the key to the main table and the data field. Then we could simply delete the rows when they are no longer needed. (And then do some sort of shrink.) However, this would be a much more difficult change to make than simply making the existing field nullable.  Note: I actually don't care so much about making the database file smaller, but I do care about the newly freed up space becoming re-usable.  Over 90% of the DB size is this one field. I'm at 3TB already.
117963
Let's say I have a char* str = "0123456789" and I want to cut the first and the last three letters and print just the middle, what is the simplest, and safest, way of doing it?  Now the trick: The portion to cut and the portion to print are of variable size, so I could have a very long char*, or a very small one.
72896
I'm looking for a javascript that can limit the number of lines (by line I mean some text ended by user pressing enter on the keyboard) the user is able to enter in textarea. I've found some solutions but they simply don't work or behave really weird. The best solution would be a jquery plugin that can do the work - something like , but it should be able to limit text line count not character count.
34971
I would like to cat file, but with limit to max length to each line. For example I a have file with 10 lines each have 10000 characters and I would like to print first 100 characters from each line. Is something like that possible with cat or some alternative? thx.
13944
I have to grep through some JSON files in which the line lengths exceed a few thousand characters. How can I limit grep to display context up to N characters to the left and right of the match? Any tool other than grep would be fine as well, so long as it available in common Linux packages.  This would be example output, for the imaginary grep switch Ф:  $ grep -r foo * hello.txt: Once upon a time a big foo came out of the woods.  $ grep -Ф 10 -r foo * hello.txt: ime a big foo came of t
77617
When I add LIMIT 1 to a MySQL query, does it stop the search after it finds 1 result (thus making it faster) or does it still fetch all of the results and truncate at the end?
73925
Earlier today a question was asked regarding .  The top answer, at time of writing, suggests in PHP just using htmlspecialchars and mysql_real_escape_string.   My question is: Is this always enough? Is there more we should know? Where do these functions break down?
112694
What mysql functions are there (if any) to trim leading zeros from an alphanumeric text field?    Field with value "00345ABC" would need to return "345ABC".
106219
On my intranet, developed with SharePoint 2013, I have a WebPart for Announcement.  People who makes Announcement have no text limit for that, but I would like to limit it at 3 lines the text on view.(to see the complete Announcement, people have to click on the hyperlink Title)  I have tried to add a calculated column which return the body column but limited to 200 character.  I didn't found this kind of formula.  Is there another solution for limiting the view to 3 lines instead of the entire Announcement?
50893
How do I truncate column "test10" to 5 characters from Unix command line?  From this  test1,test2,test3,test4,test10,test11,test12,test17 rh,mbn,ccc,khj,ee3 eeeeeEeee ee$eeee e.eeeee2eeeee5eeeeeeee,a2,3,u hyt,bb,mb,khj,R ee3ee eeEeee ee$eeee e.eeeee2eeeee5eeeeeeee,a,5,r mbn,htr,ccc,fdf,F1ee eeeeEeee ee$eeee e.eeeee2eeeee5eeeeeeee,a,e,r   To this  test1,test2,test3,test4,test10,test11,test12,test17 rh,mbn,ccc,khj,ee3 e,a2,3,u hyt,bb,mb,khj,R ee3,a,5,r mbn,htr,ccc,fdf,F1ee ,a,e,r