Jump to content

spliting paragraphs harmoniously


tallberg

Recommended Posts

Hi i have a string. containing br ' s at the end of a paragraph.

I would like to split the string in to variables or array element after a number of charectors and after a br

I think the array option would be best as it will help with the paging of long texts.

So far with the following i get the a nice crop after 1000 charectors and at the last occurance of the br.

Any br's in the code will have the <> removed as they formate.

Thanks for any help!

[quote]$p_descriptionF = substr($p_description,0,1000);

$lastbr = mb_strrpos($p_descriptionF,"br");

$p_descriptionF = substr($p_descriptionF,0,$lastbr);

echo $p_descriptionF;

// find the next part

$p_descriptionS = substr($p_description,1000,strlen($p_description));

echo $p_descriptionS;[/quote]

Link to comment
https://forums.phpfreaks.com/topic/35343-spliting-paragraphs-harmoniously/
Share on other sites

I would imagine that using

[code]
$lastbr = mb_strrpos($p_descriptionF,"br");
[/code]

is a bad idea, it will find false positives where your string may contain the word for example "brian", "break", "breakfast"

Is there a specific reason why you are not including the full tag in that strrpos? (or did I miss something :D)
splitting it into array elements would just involve [url=http://www.php.net/explode]explode[/url]. if the reason you're only using 'br' (ie, not the full tag) is to cater for both < br > and < br />, then a quick str_replace will help:

[code]
<?php
$text = str_replace('<br>', '<br />', $text);

$paragraphs = explode('<br />', $text);
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.