ibnclaudius Posted August 1, 2012 Share Posted August 1, 2012 Is there a better way to do this? $formatted_bloomp = '<div data-id="' . $bloomp['id'] . '" class="bloomp invisible">'; if ($bloomp['image_id']) { $formatted_bloomp .= '<div class="media image">'; $formatted_bloomp .= '<img src="' . base_url('upload/image/' . $bloomp['image_id']) . '">'; $formatted_bloomp .= '</div>'; } elseif ($bloomp['video_id'] && $bloomp['video_provider']) { $formatted_bloomp .= '<div class="media video">'; if ($bloomp['video_provider'] == 'youtube') { $formatted_bloomp .= '<iframe width="310" height="233" src="http://www.youtube.com/embed/' . $bloomp['video_id'] . '?rel=0&wmode=transparent&iv_load_policy=3&color=white" frameborder="0" allowfullscreen></iframe>'; } if ($bloomp['video_provider'] == 'vimeo') { $formatted_bloomp .= '<iframe src="http://player.vimeo.com/video/' . $bloomp['video_id'] . '?color=#ffffff" width="310" height="233" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; } $formatted_bloomp .= '</div>'; } $formatted_bloomp .= '<span class="text">' . $bloomp['text'] . '</span>'; $formatted_bloomp .= '<div class="info">'; $formatted_bloomp .= '<span>'; $formatted_bloomp .= '<a class="author" href="#">'; $formatted_bloomp .= '<img src="' . base_url('upload/picture/' . $bloomp['author_picture']) . '">'; $formatted_bloomp .= '<span class="name">' . $bloomp['author_name'] . '</span>'; $formatted_bloomp .= '</a>'; $formatted_bloomp .= '</span>'; $formatted_bloomp .= '<span>' . $bloomp['likes_number'] . ' curtidas</span>'; $formatted_bloomp .= '<span>' . $bloomp['comments_number'] . ' coment?rios</span>'; $formatted_bloomp .= '</div>'; if ($bloomp['comments_number'] > 0) { $formatted_bloomp .= '<div class="comments">'; foreach ($this->_CI->quickstart_model->read_comments(3, $bloomp['id']) as $comment) { $formatted_bloomp .= '<div data-id="' . $comment['id'] . '" class="comment clearfix">'; $formatted_bloomp .= '<a href="#"><img class="float-left" src="' . base_url('upload/picture/'. $comment['author_picture']) . '"></a>'; $formatted_bloomp .= '<span class="float-right">'; $formatted_bloomp .= '<a href="#">' . $comment['author_name'] . '</a> ' . $comment['text']; $formatted_bloomp .= '</span>'; $formatted_bloomp .= '</div>'; } if ($bloomp['comments_number'] > 3) { $formatted_bloomp .= '<div class="comment all">'; $formatted_bloomp .= '<a href="#">Todos os ' . $bloomp['comments_number'] . ' coment?rios...</a>'; $formatted_bloomp .= '</div>'; } $formatted_bloomp .= '</div>'; } $formatted_bloomp .= '</div>'; return $formatted_bloomp; Quote Link to comment https://forums.phpfreaks.com/topic/266555-huge-string/ Share on other sites More sharing options...
Mahngiel Posted August 1, 2012 Share Posted August 1, 2012 it is in a function? is it on the presentation page? can you use an array? Quote Link to comment https://forums.phpfreaks.com/topic/266555-huge-string/#findComment-1366008 Share on other sites More sharing options...
ibnclaudius Posted August 1, 2012 Author Share Posted August 1, 2012 It's a function to format the bloomp (post). Quote Link to comment https://forums.phpfreaks.com/topic/266555-huge-string/#findComment-1366015 Share on other sites More sharing options...
Mahngiel Posted August 1, 2012 Share Posted August 1, 2012 I generally avoid what you're doing. I would separate the concerns of image versus video, since they should be in their own containers anyway. From there, you can just do what you're doing in the view Quote Link to comment https://forums.phpfreaks.com/topic/266555-huge-string/#findComment-1366024 Share on other sites More sharing options...
Christian F. Posted August 1, 2012 Share Posted August 1, 2012 I'd use templates. Either in the form of a template engine, or via sprintf (). Something like this: // At the top of the page, or perhaps in a different file. $postTemplate = <<<PostTemp <span class="text">%1\$s</span> <div class="info"> <a class="author" href="#"><img src="%2\$s"> <span class="name">%3\$s</span></a> <span>%4\$d curtidas</span> <span>%5\$d comentarios</span> </div> PostTemp; // Inside the function that writes the post. $formatted_bloomp .= sprintf ($postTemplate, htmlspecialchars ($bloomp['text']), rawurlencode (base_url ('upload/picture/' . $bloomp['author_picture'])), htmlspecialchars ($bloomp['author_name']), $bloomp['likes_number'], $bloomp['comments_number']); Quote Link to comment https://forums.phpfreaks.com/topic/266555-huge-string/#findComment-1366026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.