PHP:爆炸后合并文本
我使用爆炸将文本分成几部分,然后使用 foreach 在文本中查找一些内容。
$pieces = explode(' ', $text);
foreach ($pieces as $piece) {
Some Modification of the piece
}
我的问题是如何将这些碎片重新组合在一起?这样我就可以对文本进行自动换行。 有些像这样:
piece 1 + piece 2 + etc
Using explode I broke up the text into pieces, then us the foreach to look for a few thing in the text.
$pieces = explode(' ', $text);
foreach ($pieces as $piece) {
Some Modification of the piece
}
My questions so how can I put those pieces back together? So I can wordwrap the text.
Some like this:
piece 1 + piece 2 + etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您将使用
implode()
函数。http://php.net/manual/en/function.implode.php
编辑:可能是有史以来最具误导性的问题。
如果您尝试对正在构建的图像进行自动换行,也许您可以使用 float:left 样式将它们全部放入单独的 div 中。
You would use the
implode()
function.http://php.net/manual/en/function.implode.php
EDIT: Possibly the most misleading question ever.
If you're trying to word wrap the images you're constructing, perhaps you could put them all in individual div's in order with the float:left style.
这是我的看法
Here's my take
首先,如果你想在内联循环中修改每个
$piece
,你必须将这些项目作为引用进行循环:当循环完成时,你可以产生使用
join()
再次生成单个字符串:(join()
的第一个参数是将各部分粘合在一起的分隔符。使用最适合您的应用程序的内容。)First of all, if you want to modify each
$piece
in the loop inline, you have to loop over the items as references:When the loop is finished, you can produce a single string again by using
join()
:(The first parameter to
join()
is the separator that glues the pieces together. Use whatever fits your application best.)到目前为止的所有答案都使它变得比实际情况要困难得多。为什么不在修改时将其放回原处呢?我想这就是您正在寻找的。
All of the answers so far make it much more difficult than it is. Why not put it back together as you modify it? I think this is what you are looking for.
$pieces = implode(' ', $pieces);
$pieces = implode(' ', $pieces);
问题很令人困惑,但是这样的事情会起作用吗:
Question is quite confusing, but would something like this work: