Hi All
I download a free chat script that in it's php files all of php code blocks start with <?php= instead of <?php or <? for print variables and constants that causes some problems and show error messages .
i want to know that how to solve this problem for php script work correctly
in your server's php config (php.ini file)
add
short_open_tag = On
At my understanding this <?php= is wrong..
Your currently problem is not the short open tags <?, but this code
<?=
means you are doing exactly this
<?php echo $someVar;
so all you have to do is change for the correct syntax.
Related
I have a PHP file (myFile.php) that parses XML, and assigns the data I need to a variable ($myVar). I need to echo this variable on an HTML page. I’ve tried adding <?php include ‘/myFile.php’; echo $myVar; ?> to the HTML file to no avail, however if I call the script itself (http://localhost/myFile.php) and add echo $myVar; to the end of the file the data is displayed as expected.
Am I missing something simple? I’m running PHP7 on a Linux Apache server - is there a setting somewhere that I need to change? I’ve used this syntax in the past without issue.
Thank you for the second set of eyes!
Try the following:
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/myFile.php';
echo $myVar;
?>
I have recently started using the PHP shorthand <?= ?> tags to echo variables etc in my PHP scripts. However I find if I want to then comment out the variable, e.g. <?= //$myVariable; ?> i get a syntax error.
Is it safe to just do this: <?//= $myVariable; ?>
Many Thanks!
The short tag
<?= ... ?>
is translated into
<?php echo ...; ?>
So to comment it out, you have to put something into ... that always shows up as empty. Here's the shortest I can come up with:
<?= false && ... ?>
This works because echo false echoes nothing.
There's no documentation supporting it, so it might be an old compatibility hack, but the following seem to work:
<?//= ... ?>
and
<?/*= ... */?>
Since they're undocumented, I wouldn't depend on them for anything important, but you could use them if you're just temporarily commenting something out while debugging.
So on the question of why <?/*=...*/?> and <?//=...?> work is because there's a PHP feature called short_open_tag, that lets you skip putting php after <? and just go with something like <? echo ...; ?>. It can be disabled in the INI file, and before v5.4 the short hand wouldn't work unless it was enabled. So as long as you're in control of your INI file you should be OK.
BUT, I just checked our 5.6.31 system (it's old yes), but when the short_open_tag is set to false the <? ... ?> get emitted directly to the client as if it were HTML text. So, it may be that you just aren't seeing the text because the browser isn't rendering it.
I'm working with PHP and HTML, but I have an issue popping up whenever I write some PHP code. An example of this is as follows:
<?php
echo "<h2>Hello?</h2>";
$var = 5;
echo "You have $var minutes to go.";
?>
What this ends up outputting on screen is:
Hello?"; $var = 5; echo "You have $var minutes to go."; ?>
But what I want to happen is this:
Hello? You have 5 minutes to go.
Is there something I'm forgetting to do? It doesn't seem to matter whether or not I add the HTML preamble, or if I put a tag like around the second echo line. Does anyone have any advice?
EDIT: Apparently I have failed to parse PHP correctly. This computer is new and I have XAMPP installed on it, but nothing else. Did I miss something I needed in order to use PHP?
That sounds like if the php code wasn't interpreted.
Make sure to have the code in a file with a filename ending with .php and that PHP is installed/enabled on your server.
The PHP isn't being parsed properly.
Make sure you are saving your files as .php
If you are running this locally through WAMP the make sure to use localhost in your URL because if your URL looks like this file:///C:/wamp/www/index.php then that is incorrect.
I think CakePHP uses .ctp files so that could also be an issue
You can setup Apache to interpret any file extension as PHP
make php and html different.so things become much easier.
try like this:
<h2>Hello?</h2>
<?php
$var = 5;
?>
You have <?php echo $var;?> minutes to go.
<?php if (arg(1) == 40): ?>
<?php
$block = module_invoke('views', 'block_view', 'home_rotator-block');
print render($block['content']);
?>
<? endif; ?>
For some reason this code is causing causing an unexpected end of file error pointing to the end of the file. I know that this code is valid because it works on my other server. Does anyone have any ideas why this might be throwing the error?
Note: I know it can be formatted differently(without the inside the if statement.
I get the same error when I comment out the $block line and the print line.
Short PHP tags may not be supported on the new server. Instead of using the short tags <? and ?>, use the full ones: <?php and ?>
Or, if you want to enable that on your new server, just change the directive in your php.ini file:
short_open_tag=On
But however, <?php is the official standard and I recommend you use it everywhere so you won't have to change it every time you switch between servers.
You're using short tags for the last line. This could very well not be enabled on your server. Check php.ini to be sure.
Maximus2012 was able to answer the question. I had to to change <? to <?php.
Thanks Maximus2012
I'm working with a legacy code that someone had left, and it happens to be my task to re-deploy the code. I'm using Windows Server 2003, Apache 2.0.63 and PHP 5.2.10.
It doesn't work. At least, not in the way I had expected it to work. Call it bugs, if you will.
Upon inspecting, I had a suspicion that this code (which appears numerous times in the application) is the culprit.
&$this->
To illustrate the problem, I reproduce this code:
<?php
phpinfo();
//$variable = &$this->request;
?>
The code above executed beautifully and as expected. However, if I change the code to:
<?
phpinfo();
//$variable = &$this->request;
?>
The code misbehaves, and produce this result on the screen instead, which of course, totally unwanted and unexpected.
request; ?>
Now, the code is littered with the similar code as above, and as such, the application now produce output on the screen similar to this one:
request; $user = &$this->user; // This is comment return false; ?>
for a code that reads as:
<?
$request = &$this->request;
$user = &$this->user;
// This is comment
return false;
?>
I had tried to change every <? with <?php whenever &$this-> rears its ugly head, but most of the time, it introduces a new error instead.
I reinstalled PHP and Apache, even using another version of PHP (5.2.6) and it still won't work. I deployed the code in my localhost (Mac OS X, PHP 5.2.8 and Apache 2.0.63) and it worked without a hassle.
Please, anyone, any enlightenment will more than suffice.
In your php.ini, you need to set the following directive:
short_open_tag = On
From the manual:
Tells whether the short form (<? ?>)
of PHP's open tag should be allowed...
If you have time on your hands, you may want to consider replacing all those short tags '<?' with the full-form ones <?php, for better portability (see what just happened to you? :)
my recommendation is not to use open tags, because it can interfere with <?xml codes.
I also had that problem before, just go and replace all <?php to <? , and then again all <? to <?php.
In this way you won't get any
<? <-- one space after the '?'
and
<?php <-- one space after the 'p'
hope this will help...
If you want to use the short tags:
("<?")
they need to be enabled in you php.ini. See this link.