Jump to content

[SOLVED] Shorthand PHP??


tqla

Recommended Posts

I am working on a script that has lines like this:

<iframe src="script.php?card_id=<?=$_GET['card_id']?><?=isset($_GET['prv'])?'&prv='.$_GET['prv']:''?>" width="638" height="848" scrolling="no" frameborder="0"></iframe>

 

My goal is to get it out of an iFrame and just use includes but I have never seen this before:

<?=isset()

 

Is this some kind of php shorthand? What does it mean? Thanks.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/156470-solved-shorthand-php/
Share on other sites

<?=$some_variable?> is the same as <?php echo $some_variable; ?>

 

In PHP you can use the short open tag, as long as it is set to be allowed in your php.ini

 

short_open_tag 1/0

 

You can start a script with <? instead of<?php

 

Most people use the long open tag though because it makes their scripts more portable. Also <? is used in other programming languages, if any of those installed on the server, it will try and guess which programming language to use so could end up with problems.

 

The script you have also uses what's known as the ternary operator.

 

This code in your script:

<?=isset($_GET['prv'])?'&prv='.$_GET['prv']:''?>

Is the same as doing:

<?php

if(isset($_GET['prv']))
{
    echo '&prv=';
}
else
{
    echo '';
}

?>

Link to comment
https://forums.phpfreaks.com/topic/156470-solved-shorthand-php/#findComment-823925
Share on other sites

I have just editted my first post.........

 

When you do the short open tag with the equals sign after it like this

 

<?=$hello_world?>

 

It echos whatever is between the = and the final ?

 

isset() returns true or false, so if you were to do <?=isset($_GET['var'])?> then it would echo 0 or 1 on the page.

Link to comment
https://forums.phpfreaks.com/topic/156470-solved-shorthand-php/#findComment-823936
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.