Is there anyway to convert an html response to string in php. let me expalin through an example.
<?php
function printTitle($title="Welcome"){
?>
<div class='mainTitle'>
<div class='titleLogo'>
</div>
<div class='titleString'>
<?php echo $title; ?>
</div>
</div>
<?php
}
?>
Here calling this function anywhere will output html showing title. Now what I need is to convert this response into string value so that it can be passed as json response like:
$response=array("title"=>printTitle(),"sidebar"=>getSideBar());
echo json_encode($response);
I want to do it like this so that I can fetch title and sidebar via ajax.
One way to do it is like:
<?php
function printTitle($title="Welcome"){
$ret="<div class='mainTitle'>
<div class='titleLogo'>
</div>
<div class='titleString'>
". $title ."
</div>
</div>";
return $ret;
}
?>
but this makes html really a mess.