Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to call variable with in variable and below attempts are working fine
Attempt 01:
<?php
$var1 = "Hello";
echo $var1;
?>
Attempt 02:
<?php
$view = '$var1 = "Hello";
echo $var1;';
echo $view;
?>
But I'm trying to call variable without using "echo" or "print" command, as mentioned below
<?php
$view = '$var1 = "Hello";
echo $var1;';
$view;
?>
Is there any other way to achieve this? Please advise.
<?php
$view = '$var1 = "Hello";
echo $var1;';
eval($view);
?>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I was trying to get variable value from a page and echo it out in another page
for example I have 2 pages pg1.php and pg2.php:
On pg2.php I have:
<?php
$vr = "Hello";
?>
Now I want to echo this out on pg1.php, I have tried this:
<?php
require "pg2.php";
echo $vr;
?>
It works, but the problem is whatever else I have on pg2.php will be displayed on pg1.php.
It would be best to restructure your code so that variables are defined in one file that then includes another file with output etc.
<?php
// vars.php
$vr = "Hello";
?>
<?php
// pg1.php
require "vars.php";
echo $vr;
?>
<?php
// pg2.php
require "vars.php";
// other stuff
// ...
// ...
?>
But for this issue in general, buffer output and then delete the buffer:
<?php
// pg1.php
ob_start();
require "pg2.php";
ob_end_clean();
echo $vr;
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a PHP file containing some variables and need to echo them multiple times in another file.
file1:
<?php
//some calculating going on
$var1 = 5;
$var2 = 2;
?>
file2:
<?php
echo $var1;
echo $var2;
?>
<?php
echo $var1;
echo $var2;
?>
How could this be achieved?
Your file2.php should include("file1.php"), like:
file2.php
<?php
include("file1.php");
echo $var1;
echo $var2;
?>
Assuming they're both in the same directory.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
if ((isset($_GET['Menu']) && $_GET['Menu'] == "1" && $_GET['Overview']==1)
{
echo '$_GET['Overview']'
}
if statement to receive parameter from the URL
Because you cannot use if the way you do. Split up the echo, then it should work:
echo "<li><a " ;
if($_GET['Menu']==1) { echo 'class="select"'; }
echo " href=javascript:setParam('Menu',1);>Networks</a></li>";
$x="";
if($_GET['Menu']==1)
$x= 'class="select"';
echo "<li><a>".$x." href=javascript:setParam('Menu',1);>Networks</a></li>";
Im partial to sprintf for concatenation, but thats just me:
echo sprintf('<li><a %s href=javascript:setParam(\'Menu\',1);>Networks</a></li>',
$_GET['Menu']==1 ? 'class="select"' : '');
You need to echo every part of your code:
echo "<li><a ";
if($_GET['Menu']==1) { echo 'class="select"'; }
echo " href=javascript:setParam('Menu',1);>Networks</a></li>";
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I got an echo of an class value but would like to assign this value to an Variable:
<p class="<?echo $test="listprice"?>"></p>
I thought about something like this:
<?$testing = echo $test="listprice"?>
But this doesnt seem to work. Is it possible to get the class echo?
When you $test = "listprice"; you are already assigning it to the variable $test. To assign it to the variable $testing if you really want to then you would do this:
$testing = $test;
// display the new variable
echo $testing;
try to separate assignment and output:
<?
$test="listprice";
?>
<p class="<? echo $test; ?>"></p>
Use short open tag of php <? ?>
<p class="<?=$test="listprice"?>">Something</p>
More about
it should be
<?php
echo $test = "listprice";
echo $name = "ankit";
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
<?php
$response = file_get_contents("http://api.trakt.tv/shows/trending.json/5d7588c188eeea0074b8d2664d12fffc");
$result = json_decode($response, true);
echo $result['title'][0];
echo "<br>";
echo $result['network'][0];
echo "<br>";
echo $result['air_day'][0];
echo "<br><img style='width:200px;' src='";
echo $result['images'][0]['poster'];
echo "'>";
?>
Ain't working. I don't know why.
I use the the trakt.tv shows API.
Write
echo $result[0]['title'];
instead of
echo $result['title'][0];
Besides, PHP's echo function will print integers and strings, but will fail with array-alike structures. You could use var_dump or var_export instead. Thanks to them, you could scan the structure and you wouldn't ask this question ;)