Jump to content

define function not working


freephoneid

Recommended Posts

Hi,

  Can any one tell me why define is not working below:

 

<?php

include("lang/default/macro.php");

?>

 

<html>

<head>

<title><?=title?></title>

</head>

<body>Hello World</body>

</html>

 

My macro file contains following:

<?php

define("title","I'm great");

?>

 

It prints title as "?=title?" rather than reading it from macro.php. However below code works fine:

 

<?php

include("lang/default/macro.php");

?>

 

<html>

<head>

<title><? echo constant("title"); ?></title>

</head>

<body>Hello World</body>

</html>

 

I want to use the macro using <?=title?> format. Can any one help me?????

 

Thanks!!!

Link to comment
https://forums.phpfreaks.com/topic/110989-define-function-not-working/
Share on other sites

test.php

=======

<?php
include("lang/default/macro.php");
?>

<html>
   <head>
   <title><?=title?></title>
   </head>
   <body>Hello World</body>
</html>

 

macro.php

========

<?php
     define("title","I'm great");
?>

 

Now, when I run test.php, it does not display the title tag??????

 

Any help would really be appreciated!!!

 

It promotes sloppier coding instead of just doing it normally.  And why wouldn't you code for portability?  What if you had to switch servers and your new host didn't support short tags?

 

I'd never use a shared hosting solution. I wouldn't host somewhere that didn't give me full access to the box that I'm paying for.

It promotes sloppier coding instead of just doing it normally.  And why wouldn't you code for portability?  What if you had to switch servers and your new host didn't support short tags?

 

I'd never use a shared hosting solution. I wouldn't host somewhere that didn't give me full access to the box that I'm paying for.

 

Not you, necessarily.  And based on the posts I've read on this forum, tons of "PHP coders" (lol, barely) try to find free hosts and garbage like that.  So that's why you should always code for portability.  =/

Short open tags are already turned off by default in php.ini recommended settings. This is the first step in depreciating and then removing a feature. Anyone using a setting against php.net recommendations is operating at his own risk of needing to go back and change his code should the setting be removed. I for one like to write code once and release it knowing that I won't have to revisit it just because I used a feature that won't be parsed on some servers when it can be written so that it will always be parsed by simply typing a few characters a handful of times in any file.

 

Go a head and use short open tags if you don't have any aspirations to become a coder that will distribute or sale his code to others, where the person receiving the code might not have the ability to turn on short open tags.

Firstly, they're off by default in PHP6, which will open up any time now:

 

; - short_open_tag = Off          [Portability]

;    Using short tags is discouraged when developing code meant for redistribution

;    since short tags may not be supported on the target server.

; NOTE: Using short tags should be avoided when developing applications or

; servers which are not under your control, because short tags may not

; be sure not to use short tags.

short_open_tag = Off

 

Secondly, PHP5 has this in its PHP.ini:

 

; NOTE: Using short tags should be avoided when developing applications or

; servers which are not under your control, because short tags may not

; be sure not to use short tags.

 

 

Firstly, they're off by default in PHP6, which will open up any time now

 

I just downloaded php6 to see if that was the case.

 

Snapshot php6.0-200806191830.tar.bz2

php.ini-dist

 

; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = On

Look in the php.ini-recommended file. 

 

[email protected]:/usr/local/php6/lib$ cat php.ini-recommended | grep 'short'

; - short_open_tag = Off          [Portability]

;    Using short tags is discouraged when developing code meant for redistribution

;    since short tags may not be supported on the target server.

; NOTE: Using short tags should be avoided when developing applications or

; servers which are not under your control, because short tags may not

; be sure not to use short tags.

short_open_tag = Off

^D

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.