Are they equal in safeness? I was informed that using
<?=$function_here?>
was less safe, and that it slows down page load times. I am strictly biased to using echo.
What are the advantages/disadvantages?
Are they equal in safeness? I was informed that using
<?=$function_here?>
was less safe, and that it slows down page load times. I am strictly biased to using echo.
What are the advantages/disadvantages?
Try this
<IfModule mod_php5.c>
php_value short_open_tag 1
</IfModule>
This would solve the problem
You can use the special tags:
<?= get_info(); ?>
Or, of course, you can have your function echo the value:
function get_info() {
$something = "test";
echo $something;
}
Call one function inside another and it will work:
<meta name="twitter:image" value="<?=
str_replace(
"367.jpg",
"150.jpg",
substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4)
)
?>" />
Or do it step-by-step saving to the variable:
# remove tail
$imageSrc = substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4);
# replace size
$imageSrc = str_replace("367.jpg", "150.jpg", $imageSrc)
<meta name="twitter:image" value="<?= $imageSrc ?>" />
Option 2 gives you the most flexibility when reusing the code. Next time you use it, you may not want to echo it out directly, but to perform other actions on it, store it for later etc
<?
and<?=
are called short open tags, and are not always enabled (see theshort_open_tag
directive) with PHP 5.3 or below (but since PHP 5.4.0,<?=
is always available).Actually, in the php.ini-production file provided with PHP 5.3.0, they are disabled by default:
So, using them in an application you want to distribute might not be a good idea: your application will not work if they are not enabled.
<?php
, on the other side, cannot be disabled -- so, it's safest to use this one, even if it is longer to write.Except the fact that short open tags are not necessarily enabled, I don't think there is much of a difference.