I have an enormous file of HTML that I'd like to convert to one variable for output. So, something like:
<div class="section">
<h3>hey<? echo $anothervar ?></h3>
<input type="submit" id="submit" name="submit" value="Submit" class="button" />
</div>
to
$myvar;
$myvar="<div class=\"section\">
<h3>hey" . $anothervar . "</h3>";
$myvar.= "<input type=\"submit\" id=\"submit\" name=\"submit\" value=\"Submit\" class=\"button\" />
</div>";
ryv. except its a HUGE file, with PHP peppered in there, but I need to get it all in one variable to pass it and then return it. Is there an automated way to do this (hopefully on windows with something like NP++?) or at least a way to automate a good portion of this rather than taking me hours and hours of going through the lines?
EDIT: Everyone is debating why I want to do that. Here's the quick and perhaps boring response; I'm writing a plugin for WordPress that takes a shortcode and replaces it with the output of a single variable; if one just echoes (as it is done in the file I was given) then WP puts the shortcode output in a different place relative to the content. So, yes, you may not want to do this but that's the reason (http://codex.wordpress.org/Shortcode_API#Overview):
When the_content is displayed, the shortcode API will parse any registered shortcodes such as "[my-shortcode]", separate and parse the attributes and content, if any, and pass them the corresponding shortcode handler function. Any string returned (not echoed) by the shortcode handler will be inserted into the post body in place of the shortcode itself.
I don't think that is a good idea. If only single variables are echoed it looks quite fine (although it's not an HTML file but a PHP file and your example <? echo $anothervar>
is neither valid HTML nor PHP).
Look at PHPs output buffering if you want to store the result in a variable:
<?php
ob_start();
?>
<!-- your stuff here -->
<?php
$output = ob_get_clean();
// Do something with output
?>
ob_start();
include("myfile.html");
$var = ob_get_clean();
You could also use this ...
$your_var = <<<EOF
a bunch of html goes here
EOF;
You can use this:
please try this code
<?php $output='';
$output.='<div class="section">';
$output.='<h3>hey<? echo $anothervar ?></h3>';
$output.='<input type="submit" id="submit" name="submit" value="Submit" class="button" />';
$output.='</div>';
echo $output;
?>