PHP字符串分为div,但有时会分词

时间:2013-06-04 00:21:26

标签: php string split

所以我的想法是,我最终会从以杂志风格格式化的数据库中显示数据。我希望将字符串拆分为列,但由于在某些浏览器中不兼容,因此不使用css3的列功能。

我已经停止了很长时间并且在一个新的div中启动了它,在那里它停止了,显然后来我会有分页的东西,但是此刻我的一些话被分成两部分。它分成另一个div。但是,这应该不会发生,因为我在这里的另一个页面上遵循了一些指令应该已经停止了分裂的话,所以我不知道发生了什么。想知道你们是否可以提供帮助。 Here是页面:

这是PHP文件“./data/lost.php”,其中字符串暂时被拉出(缩短了正文字符串,但是,在这里,你知道了):

<?php
$title = "This is where the title will go...";
$username = "[Full Name]";
$date = "[Creation Date]";
$body = 'The first season begins with a plane crash that leaves the surviving passengers of Oceanic Airlines Flight 815 on what seems to be a deserted tropical island. Their survival is threatened by a number of mysterious entities, including polar bears, an unseen creature that roams the jungle (the "Smoke Monster"), and the island\'s malevolent inhabitants known as "the Others"...';
$quote = '"This is a space reserved for a quote..."';

?>

这是页面的php:

    <?php

require_once('./data/lost.php');

function text($text,$limit,$length)
{
$newbody = substr($text, $length, strpos(wordwrap($text, $limit), "\n"));

global $newlength;
$newlength = ($length + strlen($newbody));

return $newbody;
};

echo "

<div id='wrapper'>
            <div id='articlecont'>
                    <div id='title'>". $title ."</div>
                    <div class='col12'>
                        <div id='artimage'>An Image will go here...</div>
                        <div class='col1'><span style='font-size:0.8em;'>Author: ". $username ." on: ". $date ."</span><br />
<br />". text($body,495, 0) ."</div>
                            <div class='col2'>". text($body,520, $newlength) ."</div>
                        </div>
                        <div class='col22'>
                            <div class='col31'>". text($body,390, $newlength) ."</div>
                        <div class='quote'>". $quote ."</div>
                        <div class='col32'>". text($body,260, $newlength) ."</div>
                    </div>
                    <div class='col4'>". text($body,3000, $newlength) ."</div>
            </div>
        </div>


    </body>
</html>";

?>

提前感谢您提供的任何帮助。我会继续检查回复。

1 个答案:

答案 0 :(得分:0)

检查你的substr()参数,第二个参数是start,第三个是长度

substr()