Mr Chris Posted July 2, 2009 Share Posted July 2, 2009 Hi, I'm a bit stuck and would like some help please if someone would be so kind. I have a variable which contains a long string of text. Now I have a piece of php code which finds the middle of that code and I can output some text there or an image (like below) <? //Example of what comes out of database and is assigned for the variable $text $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quam lorem, posuere et scelerisque eu, dictum eget odio."; $len = (strlen($text) >> 1) - 2; // insert at sentence boundary echo preg_replace( "/(?<=.{{$len}}[.!?])\s/", "<br />[ QUOTE WOULD GO HERE HALF WAY IN ]<br />", $text, 1); ?> Now this works fine, what i'd really like to do is half way in output a quote box i've made, but ONLY if the number of characters in the string exceeds a set amount in this case 200, otherwise it won't appear: if ($quote) && strlen($text) > 200 { echo ' <div style="float:right; display:inline;"> <div class="top_quote_box"></div> <div class="middle_quote_box">'. $quote .'</div> <div class="end_quote_box"></div> </div> '; } But I can't seem to plug the two in together, i've tried several ways but it throws up syntax errors left right and centre. Could anyone help me with this, or maybe advise a better way of doing this? Also while i'm here, would there also be a way to bolden the first paragraph only in the $text at the same time? Link to comment https://forums.phpfreaks.com/topic/164549-breaking-a-string-of-text-and-inserting-something/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.