tallberg Posted January 23, 2007 Share Posted January 23, 2007 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 brI 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 More sharing options...
Cep Posted January 23, 2007 Share Posted January 23, 2007 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) Link to comment https://forums.phpfreaks.com/topic/35343-spliting-paragraphs-harmoniously/#findComment-167054 Share on other sites More sharing options...
redbullmarky Posted January 23, 2007 Share Posted January 23, 2007 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] Link to comment https://forums.phpfreaks.com/topic/35343-spliting-paragraphs-harmoniously/#findComment-167060 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.