tags:

views:

29

answers:

3

Much like asp.net's <%=SomeVariable%> how can i enable <?php =SomeVariable ?> ?

Currently my app only works if i do <?php echo(SomeVariable) ?>

Iam using php 5.1.6

Thanks

+1  A: 

I believe you're looking for short_open_tag

Note that using short tags is generally considered bad practice because it reduces code portability. It's best to use the standard <?php echo "..."; ?> as this will run regardless of server settings.

pix0r
If im not mistaken short_open_tag setting allows for the short form directive <? DoSomething ?> to be used. It has nothing to do with 'echo' or '=' ?
It covers both <? and <?=
Greg
@Th3Fix3r: You have to read the page he linked to: “Note: This directive also affects the shorthand `<?=`, which is identical to `<? echo`. Use of this shortcut requires short_open_tag to be on. But I wouldn’t use it for portability reasons.”
Gumbo
A: 

Try not to use the ASP style open/close tags as there is a possibility that they will be deprecated in PHP 6.

Elzo Valugi
A: 

Unfortunately, php has no <?php= syntax. You either turn on short_open_tag and get <? and <?= or, you do it the sadly, proper way and do <?php print(); ?> or <?php echo();?>.

Some people (and frameworks) do a little syntactic sugar like this:

function p($toPrint) {
  print($toPrint);  
}

and that allows:

<?php p($message) ?>

But short tags really aren't desirable. Possible future deprication is one reason, but the other is that <? is the start of an XML declaration as well, and that can cause problems when you're doing this for XHTML:

<?xml version="1.0" encoding="UTF-16"?>

you'll get a nasty PHP error.

danieltalsky