HTML into PHP Variable (HTML Outside PHP Code)

HTML into PHP Variable (HTML outside PHP code)

Have you tried "output buffering"?

<?php
...
ob_start();
?>

<html>
<head>...</head>
<body>...<?php echo $another_variable ?></body>
</html>

<?php
$variable = ob_get_clean();
...
?>

PHP variable escapes outside of HTML tags

single_cat_title title will echo the value when called by default. You can override this with the second param by passing in a false value. Just make sure to add the default value '' (empty string) as the first param if you are not adding a prefix.

Update to either:

add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' );
function ebani_show_category_name() {
if ( is_product_category() ) {
$category_title = single_cat_title('', false);
?>
<div class='container'>
<div class='row ebani-title'>
<div class='col-xs-12'>
<h3 class='title'><?php echo $category_title; ?></h3>
</div>
</div>
</div>
<?php
}
}

or

add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' );
function ebani_show_category_name() {
if ( is_product_category() ) {
?>
<div class='container'>
<div class='row ebani-title'>
<div class='col-xs-12'>
<h3 class='title'><?php single_cat_title(); ?></h3>
</div>
</div>
</div>
<?php
}
}

PHP variable goes outside HTML link href string?

Change your $local variable into string. Also, put these lines on top. So, it echoes properly in the css link.

$link = "local";

if ($link == "local") {
$link = 'http://local.site/';
}
else if ($link == "online") {
$link = 'http://uploadesite.com/';
}

Sending HTML Email via PHP with Variables and External HTML Template

A better approach would be to just include the file and use ob_get_clean():

ob_start();
if($_POST['service']=="Service 1") {include 'email_template-service-1.php';}
else include 'email_template-service-2.php';
$message = ob_get_clean();

Anything echoed between ob_start() and $message = ob_get_clean() will go into the $message variable.

How to set a variable from outside of PHP tags

Don't be confuse with rush codes.

You can initialize your variable on top of your page like

<?php
$header_code =<<<EOT
<script src='jquery.js'> </script>
<script src='jquery2.js'> </script>
EOT;;

include("includes/header.php");

?>

And inside header.php

if(!empty( $header_code))
{
echo $header_code;
}

PHP echo variable and html together

<?php
$variable = 'testing';
echo <span class="label-[variable]">[variable]</span>
?>

Should be

<?php
$variable = 'testing';
echo '<span class="label-' . $variable .'">' . $variable . '</span>';
?>


Related Topics



Leave a reply



Submit