简体   繁体   English

如何将MySQL内容(文本+ HTML内容)分成几列?

[英]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. 我还无法弄清楚如何将保存在MySQL表中的600-1000个文本单词分成3个部分,以便在这些部分之间可以包含特定的Java或使图像理解更加容易。

Let's say we retrieve 800 word text from MySQL, the goal would be to do this. 假设我们从MySQL检索了800个单词的文本,目标就是这样做。

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). 并且它不打印<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. 在第二个示例中,在变量$ string的第一个实例化之后的等号前使用一个点添加到该点。

$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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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