0

I have a function...

$post_text .= '<div style="font-size: 15px; color: blueviolet">';
$post_text .= "<br>";
$post_text .= 'Text number 1.';
$post_text .= "<br>";
$post_text .= 'Text number 2.';
$post_text .= "<br>";
$post_text .= 'Text number 3, <a href="urlr">Text number 4.</a>';
$post_text .= '</div>';

echo $post_text;

This works well when used with echo $post_text;, but how do I make this function work with return $post_text; without returning html as a plain text.

5
  • Welcome. This is a bit unclear. What "function" are you referring to? What you posted isn't one. Commented Apr 26, 2020 at 9:58
  • Hi. It is to append post text inside phpbb software. Function is to big, it is actually an plugin I am trying to customize on my way, so I can't post all the code, but the point is, I need to use ".=" php operator to append existing text, but also to make appended html to not show as plain text. Commented Apr 26, 2020 at 10:04
  • What do you mean by: 'without returning html as a plain text.'? Html is plain text. Commented Apr 26, 2020 at 10:06
  • <br> shows as <br>, it does not act as an actual new line separator, I meant on that. Commented Apr 26, 2020 at 10:08
  • Here is the whole script pastebin.com/DB6TY0W9 the change needs to be done, on this part $post_text .= "\n\n" . '[url=' . $rss_item['link'] . ']' . $this->user->lang('FPB_READ_MORE') . '[/url]'; Commented Apr 26, 2020 at 10:12

2 Answers 2

1

if you have :

function text(){
$post_text .= '<div style="font-size: 15px; color: blueviolet">';
$post_text .= "<br>";
$post_text .= 'Text number 1.';
$post_text .= "<br>";
$post_text .= 'Text number 2.';
$post_text .= "<br>";
$post_text .= 'Text number 3, <a href="urlr">Text number 4.</a>';
$post_text .= '</div>';

return $post_text;
}

echo text();

You shouldn't have any issues, maybe it is another thing in your code that is causing the issue ( maybe the framework ? );

Sign up to request clarification or add additional context in comments.

3 Comments

If You want to return only text you could do use strip_tags() (php.net/manual/en/function.strip-tags.php)
Ask for clarification in/on the question.
Ok, but, well... in my case it is not echo text(); but return text();, it is huge script to post everything, and problem is there is no single echo in it, but all return, and than I get html showing as plain text.
0

You could create a function:

function post_text(){
$post_text .= '<div style="font-size: 15px; color: blueviolet">';
$post_text .= "<br>";
$post_text .= 'Text number 1.';
$post_text .= "<br>";
$post_text .= 'Text number 2.';
$post_text .= "<br>";
$post_text .= 'Text number 3, <a href="urlr">Text number 4.</a>';
$post_text .= '</div>';
return $post_text;
}

Such that you could call the function which would immediately output the return value:

'<div class="main-container"><?php echo post_text(); ?></div>'

This will be returned as plain text since the values you passed into the php variables are strings, but will be parsed as html when the function is called.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.