Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot turn off short_open_tag with ini_set

I'm embedding a javascript syntax highlighter to a PHP script that reads source file and echos it back. The js highlighter has this string on one line:

... [z,/^[^<?]+/], ...

The short_open_tag is on on this server and the <? in the string confuses the script and causes errors. I cannot turn off in php.ini or elsewhere.

I have used ini_set('short_open_tag', '0'); in the same script, but it does not take effect. What could be the problem?

Edit

In the end, I used what Col Shrapnel suggested in a comment:
I changed [z,/^[^<?]+/], to [z,/^[^<?php echo '<' .'?'; ?>]+/],

like image 784
Majid Fouladpour Avatar asked Apr 12 '11 09:04

Majid Fouladpour


3 Answers

'short_open_tag' is marked as PHP_INI_PERDIR in PHP <5.3.0, which means you can't change it with ini_set().

like image 159
user688502 Avatar answered Nov 16 '22 10:11

user688502


According to a comment on this manual page:

libkhorse at gmail dot com 06-Aug-2009 07:14:

For 'short_open_tag', though it is marked as PHP_INI_ALL in changable column, you should note the CHANGE_LOG column also:

PHP_INI_ALL in PHP <= 4.0.0. PHP_INI_PERDIR in PHP < 5.3.0

So as of 4.0, it will not work if you wanna use ini_set('short_open_tag') to change it's value on the fly.

Try using .htaccess instead:

php_flag short_open_tag off 
like image 20
Lightness Races in Orbit Avatar answered Nov 16 '22 10:11

Lightness Races in Orbit


I see no connection between your highlighter and turning short open tags off.

If some of your code gets confused with short tags, you have to rewrite your code manually, replacing short tags with long ones. Or at least run some code to do it.
But no configuration setting will do it for you.

Also, I see no way for JavaScript code to read PHP file source with all these whatever short or long tags.

It seems your problem is somewhere else.

like image 2
Your Common Sense Avatar answered Nov 16 '22 10:11

Your Common Sense