473,394 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help breaking up text for multiple pages

I was recently put in charge of heading up my company's website, and
while I have a lot of experience on the design side of things, I'm
still very new to the programming side. When I started, the website had
just gotten a revision, but the site was an utter mess, so I've been
trying to fix it up. As I've gone along, I've learned some aspects of
PHP, but my knowledge is still very limited.

Here is the problem I'm trying to fix. A backend is used to enter
information into our MySQL database, and then a page template pulls it
out to make the page. For our reviews, the PHP coding currently breaks
up the review's text so that it can be places across multiple pages.
The problem is, the way the text breaking was set up, the end of one
page and the beginning of the next are totally chaotic, with breaks
often coming mid-sentence.

Here is what I'd love: other coding automatically puts an HTML break at
the end of paragraphs, and then another in the space between one
paragraph and the next. I'd love to have the code search for when those
double breaks come up, and then break up the text after, say, every
sixth pair of HTML breaks. I'd also like the option to break the text
myself by putting in some sort of text code in the original text. At
this point, though, anything that can make the breaks more elegant
would be a huge improvement.

I really appreciate any help anybody can give me in this one. Please
remember that I know very little of PHP, and I'm not much of a
programmer anyhow, so things that you may take for granted that people
would understand about PHP, I might not know.

I tried to pull out what I thought was the current coding for the text
break. Here it is. I'd also like to get rid of the part1/part2 factor.
Before, they had the text breaking to help in fitting into the layout
around an image, but I've fixed that so I no longer need the break. So,
that portion no longer needs to be a factor.
if ($page == ""){
$page = 1;
}
$no_letters = strlen($Game_Full_Story);
$times = ($no_letters / 3800) +1;
$Game_Full_Story = wordwrap($Game_Full_Story,3800,"*#^");
$Game_Full_Story = explode ("*#^", $Game_Full_Story);
$pages = array();
for ($i=0; $i<$times ; $i++){
$part[$i] = $Game_Full_Story[$i];
if ($i != 0){
array_push($pages, $i);
}
}
$page = $page-1;
$story = $part[$page];
if (strlen($story) < 460){
$parts1 = $story;
}else{
$story = wordwrap($story,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="";
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .=" ";
}
}

Apr 27 '06 #1
4 1731
I'm a bit confused on the purpose of

$page = $page -1;

Aren't we moving from page 1 to page N? Shouldn't that be a $page++?
Anyways...

You mentioned you wanted breaks after each paragraph. I'm how that
that's what you else should look like in order to accomplish this.

}else{

$story = wordwrap($story,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="<BR>"; //inserted break here
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .="<BR>";//inserted break here
}

Could you also provide a sample of what's in your database. So as i
could understand what's being worked with and what format the data is
in.

Apr 27 '06 #2
First, I have no idea why that code is there, as I didn't put it there
myself. *heh*

Actually, let me clear up what I was saying. Right now, something
somewhere in the coding of the site puts in <br/> tags for every
carrier return. (More on that in a moment.) So, my thought was, instead
of breaking up the text for separate pages at an arbitrary place, and
possibly cut a paragraph or sentence in half, I was thinking that if I
could have the PHP code break up the text at, say, every sixth grouping
of two <br/>s together, instead of say at X number of words or
characters. That way, each page would have like six paragraphs on it,
but that would also make it so that if I have an interview with a
question, one <br/>, and then the answer, it wouldn't break up the
question and answer.

Does that make sense?

As far as what is in the database, it's just plain old text. For
example, in the backend, I'll cut the review from my text editor, and
then paste it in. Either before or after it goes into the database, it
gets the <br/> tags added to it. (If it is important which step it is,
I can check.)

Apr 27 '06 #3
if there's already <br> in the database i don't think there should be a
need to do that in your code. What you could do is remove all breaks in
the database and let the code do that for you.

Apr 27 '06 #4
m.********@gmail.com wrote:
I was recently put in charge of heading up my company's website, and
while I have a lot of experience on the design side of things, I'm
still very new to the programming side. When I started, the website had
just gotten a revision, but the site was an utter mess, so I've been
trying to fix it up. As I've gone along, I've learned some aspects of
PHP, but my knowledge is still very limited.

Here is the problem I'm trying to fix. A backend is used to enter
information into our MySQL database, and then a page template pulls it
out to make the page. For our reviews, the PHP coding currently breaks
up the review's text so that it can be places across multiple pages.
The problem is, the way the text breaking was set up, the end of one
page and the beginning of the next are totally chaotic, with breaks
often coming mid-sentence.

Here is what I'd love: other coding automatically puts an HTML break at
the end of paragraphs, and then another in the space between one
paragraph and the next. I'd love to have the code search for when those
double breaks come up, and then break up the text after, say, every
sixth pair of HTML breaks. I'd also like the option to break the text
myself by putting in some sort of text code in the original text. At
this point, though, anything that can make the breaks more elegant
would be a huge improvement.

I really appreciate any help anybody can give me in this one. Please
remember that I know very little of PHP, and I'm not much of a
programmer anyhow, so things that you may take for granted that people
would understand about PHP, I might not know.

I tried to pull out what I thought was the current coding for the text
break. Here it is. I'd also like to get rid of the part1/part2 factor.
Before, they had the text breaking to help in fitting into the layout
around an image, but I've fixed that so I no longer need the break. So,
that portion no longer needs to be a factor.
if ($page == ""){
$page = 1;
}
$no_letters = strlen($Game_Full_Story);
$times = ($no_letters / 3800) +1;
$Game_Full_Story = wordwrap($Game_Full_Story,3800,"*#^");
$Game_Full_Story = explode ("*#^", $Game_Full_Story);
$pages = array();
for ($i=0; $i<$times ; $i++){
$part[$i] = $Game_Full_Story[$i];
if ($i != 0){
array_push($pages, $i);
}
}
$page = $page-1;
$story = $part[$page];
if (strlen($story) < 460){
$parts1 = $story;
}else{
$story = wordwrap($story,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="";
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .=" ";
}
}


Well, could it be as simple as using strpos() to find the <br>s? (Actually in
this case stripos() would be better because it's not case sensitive) (Warning -
NOT tested!)

if (!isset($page) || $page == "")
$page = 1;

$pos = 0;
for ($cpage = 0; $cpage < $page; $cpage++) {
$pstart = $pos;
for ($cpar = 0; $cpar < 6; $cpar++) { // Change 6 to # of paras/page
$oldpos = $pos;
$pos = stripos($text, '<br>', $pos);
if ($pos === false) // no more found
break;
else
$pos++; // Point to next char and continue
}
}
if ($oldpos > $pstart)
echo substr($text, $pstart, $oldpos);
else
echo "End of article";

Probably not perfect, but it should get you started.

Alternatively, you could split the paragraphs into an array and just count the
number of items you need, i.e. (Again no tested)

if (!isset($page) || $page == "")
$page = 1;
$tarray = preg_split('/<br>/i', $text);
$pcount = 6; // Number of paragraphs per page
$startpar = ($page-1) * $pcount;
$endpar = min($startpar + $pcount, count($tarray)); // Don't go past end
for ($i = $startpar; $i < $endpar; $i+)
echo $tarray[$i];

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: leegold2 | last post by:
Hi, I have been looking around for a way to paginate php/mysql table output. There are a lot of hits when I google it. But unfortunately what I have tried either does not work or is imho just...
15
by: AMT2K5 | last post by:
Hello folks, I seem to have recieved a segfault within my function but am unsure on how to resolve it. I understand that it means that somewhere something is trying to access memory that is not...
87
by: Frances Del Rio | last post by:
is there a non-breaking hyphen in HTML?? for example, so a phone no. falls all on one line.. as in.. 1-800-444-5454... (and is not broken into two lines if phone no. occurs near end of a...
27
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody...
22
by: stevenkobes | last post by:
If a word has a hyphen in it, IE will permit a line break at the hyphen, but Firefox/Mozilla won't. Apparently the Firefox behavior is standards-compliant, but it is not what I want. Is there a...
2
by: Patrick | last post by:
Hello - I am wondering what the command is for breaking quoted text over multiple lines for formatting in my code. An example is MessageBox.Show("You Fool! The number of registrants cannot be 0....
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
9
by: xprotocol | last post by:
Trying to print a web page that scrolls to right a bit. I would think IE would page break by default when it gets to the end of the sheet, but it doesn't, it just cuts off the print. This only...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.