Pankyy 0 Report post Posted September 26, 2009 (edited) Hey, I wanted to ask if you think it's possible to do the following: add a breakline (AKA "\n") in the 5th of the search given(in this case something like ". "). To make it an easy example of what I want to achieve, it's just to create a different paragraph after 5 sentences.Sentence 1. Sentence 2. Sentence 3. Sentence 4. Sentence 5. Sentence 6toSentence 1. Sentence 2. Sentence 3. Sentence 4. Sentence 5.Sentence 6I'm pretty sure PHP is more than capable of doing something like that, but I lack the know-how. Can someone tell me which is the best way to do it?Thanks. Edited September 26, 2009 by Pankyy (see edit history) Share this post Link to post Share on other sites
kleong 0 Report post Posted September 26, 2009 You should be able to do it with a counter. Meaning every search result, increase the counter and then on hitting 5 (with a If-Else condition), add a '\n' and the counter resetted. Share this post Link to post Share on other sites
BuffaloHelp 24 Report post Posted September 26, 2009 I might have a solution in PHP... I would not write the entire code but I'll explain the logic.I'm assuming you are doing something in the background and retrieves X results from the searches (let's say 20 results).It is better to write a logical loop that will accommodate just about every situation, for example for 10 results, 40 results or just 2 results. So, write a loop that checks for count that is multiples of 5. Which means, every time the result is displayed in multiples of 5, insert "\n" before outputting the next result.So, loosely written, $count = "0";start the loop{ echo 'result'; $count = $count +1; if $count is multiples of 5 { echo '\n'; }continue to loop until all results are shown}I don't know your code to display the results so I'm leaving it as general as is. But I think writing a concise loop to look for multiples of 5 and then inject "\n" would be the best approach. Share this post Link to post Share on other sites
BCD 1 Report post Posted September 26, 2009 (edited) I don't know much of PHP syntax. You can do something along what BuffaloHelp has posted above. A "for" loop to check the multiples something like this: for($i=1; $i<=$totalEntries; $i++){ $checkMod = $i % 5; echo "result"; if($checkMod == 0) echo "\n";} totalEntries should contain the total number of search results to be displayed. Edited September 26, 2009 by BCD (see edit history) Share this post Link to post Share on other sites
manish-mohania 0 Report post Posted September 27, 2009 Let's suppose you have a long string of several sentences, each ending with a period *You may want to break this long string in to paragraphs, such that, each paragraph contains five sentences.You can do this way : $example_string = 'Hi, this is manish. I love to play table-tennis.'; /* take a very long strong with many sentences */$sentences = explode('.', $example_string); /* explode the string in to an array with * specified as delimiter */foreach($sentences as $i => $s) { /* iterate through the array with index as $i, sentence without * as $s */ if ($i % 5 == 0) { print '<br />'; /* if you are outputting plain text and not html text then use - '\n' instead. */ } print $s.'. '; /* sentence followed by a period * and space */} I hope, you are clear, how this is done in PHP. Share this post Link to post Share on other sites