简体   繁体   中英

How to break MySQL content(text+html content) into columns?

As a first, I'd like to mention that I understand how everyone feels towards asking questions without providing at least some trial or errors, yet this is purely a need to know knowledge, with that being said, I'll go ahead and ask.

I haven't been able to figure out how to break content let's say 600-1000 text words saved in a MySQL table into 3 sections, so that in between these sections it could include specific java or to make it easier to understand images.

Let's say we retrieve 800 word text from MySQL, the goal would be to do this.

Content    
========= Section Break [image] ==========
Content
========= Section Break [image] ==========

I've got this so far, (went ahead and tried to save problems by not including anything), but it is breaking the text in the middle of the sentence, where I'd like to break at least at the last .(dot) on that line.

$text = stripslashes($article_content); 

$first = strpos($text," ",strlen($text) / 2);
$col1 = substr($text, 0, $first);
$col2 = substr($text, $first);

echo $col1;
echo "this is the line break";
echo $col2; 

and this one it does not print the <br/> ($separator).

$separator = "<br/>";

$text = stripslashes($article_content); 
$first = ceil(strlen($text) / 3);

$string = substr($text, 0, $first);
$string = $separator;
$string = substr($text,$first,$first);
$string = $separator;
$string = substr($text,($first*2), $first);

echo $string;
  1. The first I cannot get it to break at the last .(dot) in that line.
  2. It does not print the separator, no idea why either, but the text prints just fine.

Use a dot before the equalssign after the first instantiation of the variable $string to add to it in your second example.

$separator = "<br/>";

$text = stripslashes($article_content); 
$first = ceil(strlen($text) / 3);

$string = substr($text, 0, $first);
$string .= $separator;
$string .= substr($text,$first,$first);
$string .= $separator;
$string .= substr($text,($first*2), $first);

echo $string;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM