Jump to content
xisto Community
Pankyy

Adding Line Break After Some Finds

Recommended Posts

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 by Pankyy (see edit history)

Share this post


Link to post
Share on other sites

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

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 by BCD (see edit history)

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.