php string variable code example
Example 1: set php var to html
<?php ob_start();?>
<div>Contents goes <b>here</b></div>
<?php $contents=ob_get_clean();?>
Example 2: php variables
<?php
$string = 'string';
$number = 1;
?>
Example 3: php variable in string
$a = '12345';
echo "qwe{$a}rty";
echo "qwe" . $a . "rty";
echo 'qwe{$a}rty';
echo "qwe$arty";
Example 4: php variables
<?php
#variable rules
#DATA TYPES
$output = ' Hello there Bob!!';
$num1 = 4;
$num2 =10;
$sum = $num1 + $num2;
$string1 = ' Hello';
$string2 = 'Bobby!!';
$greeting = $string1 .' '. $string2;
$greeting2 = "$string1 $string2";
$string3 = ' They\'re Here';
#making a constant
define('GREETING', ' Hello Everyone!!');
echo $sum;
echo $output;
echo $greeting;
echo $greeting2;
echo $string3;
echo GREETING;
?>
Example 5: php variable
$name = "Josh";
Example 6: PHP Variable in String
phpCopy# php 7.*
<?php
$txt = "salt";
echo "{$txt}y";
?>