I am learning php and am making a statement that proves the local variable cannot be called outside a function where it is defined.
I can't seem to get a line break come out in the statement but only a line space.
<html>
<head>
<title>Testing Global and Local Variables</title>
</head>
<body>
<?php
//Global varaible called after function
$g_test_string="this is the value in the variable outside the function at a global level!";
function printstring()
{
$l_test_string="this is the value of the variable inside the function at a local level!";
print($l_test_string);
}
//Calling statements
printstring();
echo "";
echo 'Global variable value: ' . $g_test_string;
echo 'Local variable value: ' . $l_test_string;
?>
</body>
</html>
The print out looks like this:
this is the value of the variable inside the function at a local level! Global variable value: this is the value in the variable outside the function at a global level! Local variable value:
I tried a break between the function call and echo for global variable but only produces a line space not a break.
Got to be something simple I imagine.
Many thanks
Andrew
If you want to be sure your line break is cross platform compatible, use PHP_EOL
I usually use " ". If you want the linebreak to appear in HTML, use "<br>"
.
Edit in response to comments: Here's how you pull as much PHP out of the HTML as possible.
<?php
//Global varaible called after function
$g_test_string="this is the value in the variable outside the function at a global level!";
?>
<html>
<head>
<title>Testing Global and Local Variables</title>
</head>
<body>
<?php
//Calling statements
printstring();
echo "<br>
";
echo 'Global variable value: ' . $g_test_string."<br>
";
echo 'Local variable value: ' . $l_test_string."<br>
";
?>
</body>
</html>
<?php
function printstring()
{
$l_test_string="this is the value of the variable inside the function at a local level!";
print($l_test_string);
}
Where you want a line break in PHP use either <br />
or
I used breaklines for your demo: http://www.forumalliance.net/so.php
<html>
<head>
<title>Testing Global and Local Variables</title>
</head>
<body>
<?php
//Global varaible called after function
$g_test_string="this is the value in the variable outside the function at a global level!<br />";
function printstring()
{
$l_test_string="this is the value of the variable inside the function at a local level!<br />";
print($l_test_string);
}
//Calling statements
printstring();
echo "";
echo '<br />Global variable value: ' . $g_test_string;
echo '<br />Local variable value: ' . $l_test_string;
?>
</body>
</html>
How break the line on display data one by one line on while loop and forward to dropdown id
$que="select * from parties WHERE Item_code='".$_GET['q']."'";
$run=mysql_query($que);
while($row=mysql_fetch_array($run)){
if($row['party_name'] == "")
{
echo "";
}
else
{
if($_GET['type'] == "di")
{
echo $row['Id'];
}
elseif($_GET['type'] == "did")
{
echo $row['party_name'];
}//END IF DI OR DID
}//END IF PARTY NAME BLANK
}//END WHILE