/    Sign up×
Community /Pin to ProfileBookmark

<?=$variable?> tags

Hi All,

I need to know how to switch on (or replace) the <?=$variable?> tags. I’ve installed a new wamp on a laptop and these tags don’t seem to be supported (php5.2.6).

When I run index.php, it inserts the literal <?=$variable?> instead of the variable value into the html code.

Any suggestions?

Note: The script is not for distribution. I’m not concerned about portability.

Cheers
CTB

Example code

[code=php]$somevalue = $result[‘somevalue’];
?>
<input type=’text’ value='<?=$somevalue?>’>
<?php[/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@ShortsOct 31.2008 — This will do the trick:

[code=php]
<?php echo $somevalue; ?>
[/code]
Copy linkTweet thisAlerts:
@chestertbauthorOct 31.2008 — thanks shorts.

however, before i do a global search and replace, is there a setting in php.ini that will switch <?=$xx?> back on?
Copy linkTweet thisAlerts:
@JustinOct 31.2008 — Look for shorttags in your ini file
Copy linkTweet thisAlerts:
@chestertbauthorOct 31.2008 — thanks Justin. That did the trick.

Cheers

CTB
Copy linkTweet thisAlerts:
@NogDogOct 31.2008 — Just FYI, since the short_open_tag option is not universally supported (as you've discovered), I consider it a "best practice" to always use one of the tags that are always supported (either the "<?php" or "<script type='text/php'>") so that it's never an issue. In fact, you may find you [i]want[/i] the short_open_tag option off so that it does not conflict with <?xml?> tags.
Copy linkTweet thisAlerts:
@chestertbauthorOct 31.2008 — Thanks NogDog.

You're probably right, and if what I'm writing was for general distribution, there'd be no argument at all.

However, (some would say "stupidly") I structured the code with <?=$variables?> because it was far easier to write and debug. I tried switching to <? echo $variable ;?> but it strikes me a visually messier and a little more cumbersome to type. Ah well. Such is the price of progress, I suppose, and at some point I'm sure I'll start incorporating xml so the short_open_tags will have to go.

Cheers

CTB
Copy linkTweet thisAlerts:
@NogDogOct 31.2008 — The [b]<? echo $variable; ?>[/b] option would still require that short_open_tag be turned on. :p You'd have to use [b]<?[color=red]php[/color] echo $variable; ?>[/b].

Anyway, a little extra typing now is worth it if those few seconds save you minutes or hours later trying to resolve problems. In fact, that holds true for most things that all us lazy programmers tend to avoid while coding in order to save time right now, like comments. ?
Copy linkTweet thisAlerts:
@chestertbauthorOct 31.2008 — Yeah yeah. <?php echo $variable; ?>. I meant that. :p

When the need arises, I'll suppose I'll just do a global search and replace across the whole project... maybe when it's finished and those extra keystrokes aren't an issue.

For now though, I might stick with "bad programming" and just accept condemnation and derision from my peers. ?
Copy linkTweet thisAlerts:
@felgallNov 01.2008 — Just FYI, since the short_open_tag option is not universally supported (as you've discovered), I consider it a "best practice" to always use one of the tags that are always supported (either the "<?php" or "<script type='text/php'>") so that it's never an issue. In fact, you may find you [i]want[/i] the short_open_tag option off so that it does not conflict with <?xml?> tags.[/QUOTE]

It is [B]<script language="php">[/B] that is the longest form of the PHP tag. The type attribute is for client side languages such as JavaScript and vbScript.
Copy linkTweet thisAlerts:
@NogDogNov 01.2008 — That's what I get for not checking the manual, since I'm [i]way[/i] too lazy to ever actually use that in my code (and was too lazy to check the manual, too). ?
×

Success!

Help @chestertb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...