Is there any way to save this block of code into a PHP variable ? The reason of doing this is because I want to send it through mail()
echo 'MONDAY<BR>';
query_posts('meta_key=Date1&meta_value=MONDAY');
while (have_posts()):
the_post();
if (in_category( '11' )) {
echo get_post_meta($post->ID, 'HomeSlogan', true);
} else {
the_title();
}
echo'<br>';
endwhile;
This is what zneak suggests
<?php
ob_start();
echo 'MONDAY<br>';
query_posts('meta_key=Date1&meta_value=MONDAY');
while (have_posts()):
the_post();
if (in_category( '11' )) {
echo get_post_meta($post->ID, 'HomeSlogan', true);
} else {
the_title();
}
echo'<br>';
endwhile;
$mail = ob_get_contents();
echo $mail;
ob_end_clean();
?>
You can either use string concatenation and avoid
echoaltogether, or use output buffering. Output buffering saves your script’s output into a buffer instead of sending it to the browser, so it’s easier to use if you have functions that print text and that you can’t really control.For output buffering, you might want to read about ob_start, ob_get_contents and ob_end_clean.