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
How can I display php file to the screen from this php file?
So php script should display own code.
Conditions - file and input statements are forbidden!!!
<?php
echo file_get_contents('you_php_file.php');
?>
or simply
<?php
echo file_get_contents(__FILE__);
?>
Read more about file_get_contents here and about __FILE__ here
use highlight_file so that you can get the source code in nice color formatting.
highlight_file($file_name);
If the PHP is loading, you could simply echo the code, though you have to escape the (double) quotes ofcourse:
Echo '$testvar1 = \'butterfly\';
$testvar2 = \'elephant\';';
Or if indeed you want to display all the code, donCallisto's method is better ;-)
To have a php file display its own code you could do it like so:
<?php
echo file_get_contents(__FILE__);
?>
to get another file's contents
<?php
echo file_get_contents("other_file.php");
?>
Use:
echo htmlspecialchars(file_get_contents($file));
(otherwise, if you use echo file_get_contents($file);
you have to click View>Source on page, to see the content, as they are put in <>)
Related
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 7 years ago.
Improve this question
How can i print variable in brackets? Like ip board, for example I have this code:
<?php
$variable = "test";
?>
<div class="test">{$variable}</div>
How can I do this? Not
echo $variable;?>
but {$variable} ! Thanks in advance :3
It's called concatenation and it uses '.' to string things together...
<div class="test"><?php echo '{'.$variable.'}' ?></div>
you can use it like this
<?= $variable ?>
Use a php templating engine. Best for you is that use Laravel and Balde
yes, you can just do it like
<?php
$variable = "test";
?>
<div class="test"><?= $variable; ?></div>
but if you want to use above approach(your one) you've to use blade templating engine
have a look
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 have html code loaded in array $gh[0] and i am coonverting it to plain text
if i compare with same text loaded into new variable it doesn't works
can someone help with the issue, what should be exact value in $a to match the content in $gh[0]
i want comparsion to be working , what will be output if $gh[0] is converted into plain text especially line break
<?php
$gh[0]="Net inventory (used in)/from<br>Production Activities"
$fg=$gh[0]->plaintext;
$a="Net inventory (used in)/from Production Activities"
if($a == $fg)
{
echo "match";
}
else
{
echo "No match";
}
?>
What about just stripping all elements from the input?
$gh[0]= strip_tags($gh[0]);
If you want to know what the value (of $fg) is, why don't you check it?
There's echo, print_r and var_dump.
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 was wondering if you could give two values to a class and then acces to the second one by POST, something like this (part of the code):
echo "<select name='selecttsk' id='selecttsk'>";
while($w = $bd->obtener_fila($tasker, 0)){
echo "<option class='opcion1' value ='".$w[1]/$w[2]."'>".$w[0]."</option>";
}
echo "</select>";
?>
and then i need to do something like this in other file
$var = $_POST[selecttsk];
but i need $w[2]
thanks
I suppose your $_POST['selecttsk'] does have the values in the following format:
"foo/bar"
You could use "explode" in PHP to get the second part (bar), for example:
$postvar = $_POST['selecttsk'];
$vars = explode("/", $postvar);
// Then
$var = $vars[1]; // Will be the $w[2] from the form
Look into: http://php.net/explode
Beware that if $w[1] or $w[2] ever contains a "/" you might get unexpected results, you could use the limit function of explode to mitigate that issue.
However - I would generally not recommend this workflow.
Why do you need to send two variables with one select?
(could you show us som example of what $w contains)
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 8 years ago.
Improve this question
I am very new in PHP programming and my line break does not working.
Please find the bug, in the below code:
<?php
echo "hello World \n ";
//the next section will demonstrate the use of variable
$name='Nadim Emon';
echo "Hello $name";
?>
Here is the working code, direct use this code it will work
<?php
//the next section will demonstrate the use of variable
$name='Nadim Emon';
echo nl2br("hello World.\nHello $name.");
?>
The line break works fine, but the browser displays HTML entities, not line breaks.
Change your code to this:
<?php
echo "hello World <br> ";
//the next section will demonstrate the use of variable
$name='Nadim Emon';
echo "Hello $name";
?>
Browsers display code that has specific values and generally ignores whitespace. You can get around this by using some very specific HTML tags such as <pre> which will then maintain line breaks in your output.
There is also another option such as PHP's nl2br which will then replace any line breaks with HTML code to place line breaks in as you expect them to be displayed by a browser.
you can use the <br/> tag
<?php
echo "hello World"."<br/>";
//the next section will demonstrate the use of variable
$name='Nadim Emon';
echo "Hello $name";
?>
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
Is it possible to have use a php variable in multiple positions in the code? For example
<?php
some code here with a certain variable called var
?>
some html code
<h3> <?php $echo $var ?> <h3>
Yes! PHP is wonderful that way. I like to think of it as an overlay on top of my HTML code that simply acts when I tell it to. You can test it for yourself and see - that's the best way to learn :)
This works fine:
<?php
$a = "hello world!";
?>
<h3> <?php echo $a ?> <h3>
If a file is being interpreted as a PHP script you may think of it as a entire piece of code, the HTML code between scripts works like a echo. So, if you declare a variable in any part of the script, if it is on the global scope, it is available for each of the scripts declared. Just be careful with the scopes where you declare de variables. If you declare a variable inside a function, it will be available inside the function.