Jump to content

Recommended Posts

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;

Link to comment
https://forums.phpfreaks.com/topic/266555-huge-string/
Share on other sites

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']);

Link to comment
https://forums.phpfreaks.com/topic/266555-huge-string/#findComment-1366026
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.