Как убрать quot вместо кавычек
Argument ‘Topic id’ is null or empty
Сейчас на форуме
© Николай Павлов, Planetaexcel, 2006-2023
info@planetaexcel.ru
Использование любых материалов сайта допускается строго с указанием прямой ссылки на источник, упоминанием названия сайта, имени автора и неизменности исходного текста и иллюстраций.
| ООО «Планета Эксел» ИНН 7735603520 ОГРН 1147746834949 |
ИП Павлов Николай Владимирович ИНН 633015842586 ОГРНИП 310633031600071 |
Как убрать quot вместо кавычек
Директиву magic_quotes_gpc можно отключить только на системном уровне и нельзя во время выполнения. Другими словами, использование ini_set() не даст никакого эффекта.
Пример #1 Отключение волшебных кавычек на сервере
Ниже указан пример, где показана установка значения Off в php.ini для этих директив. Для дополнительной информации читайте раздел руководства под названием » Как изменять параметры конфигурации».
; Волшебные кавычки ; ; Волшебные кавычки для входных данных GET/POST/Cookie. magic_quotes_gpc = Off ; Волшебные кавычки для данных, поступающих во время выполнения (например, данные из SQL, из exec() и т.д). magic_quotes_runtime = Off ; Использование волшебных кавычек в стиле Sybase (экранирование ' с помощью '' вместо \'). magic_quotes_sybase = Off
Если доступ к конфигурации на сервере невозможен, используйте .htaccess в качестве альтернативы. Например:
php_flag magic_quotes_gpc Off
В целях написания переносимого кода (код, который будет работать на любой платформе), и в случае невозможности изменения конфигурации на сервере, показан пример отключения magic_quotes_gpc во время выполнения скрипта. Этот метод неэффективен, так как предпочтительно устанавливать соответствующие директивы в другом месте.
Пример #2 Отключение волшебных кавычек во время выполнения скрипта
if ( get_magic_quotes_gpc ()) $process = array(& $_GET , & $_POST , & $_COOKIE , & $_REQUEST );
while (list( $key , $val ) = each ( $process )) foreach ( $val as $k => $v ) unset( $process [ $key ][ $k ]);
if ( is_array ( $v )) $process [ $key ][ stripslashes ( $k )] = $v ;
$process [] = & $process [ $key ][ stripslashes ( $k )];
> else $process [ $key ][ stripslashes ( $k )] = stripslashes ( $v );
>
>
>
unset( $process );
>
?>?php
User Contributed Notes 10 notes
15 years ago
I have discovered that my host doesn’t like either of the following directives in the .htaccess file:
php_flag magic_quotes_gpc Off
php_value magic_quotes_gpc Off
However, there is another way to disable this setting even if you don’t have access to the server configuration — you can put a php.ini file in the directory where your scripts are with the directive:
However, these does not propogate unlike .htaccess rules, so if you launch from a sub-directory, you need the php.ini file in each directory you have as script entry points.
9 years ago
Here’s a couple tips when using scripts on different (often shared) hosts, where ini_set doesn’t work and php directives in .htaccess causes a 500 Internal Server Error.
Firstly, copy the server’s php.ini file to your domain’s web-root folder. To find the correct paths, use phpinfo() and look for «Configuration File (php.ini) Path» and «DOCUMENT_ROOT»
It’s unlikely you’ll have access to the php.ini via FTP, so instead run a script with a simple copy command (obviously inserting your paths):
exec(«cp /usr/local/php/etc/php.ini /home/LinuxPackage/public_html/php.ini);
Edit the now-accessible php.ini file, and add settings like ‘magic_quotes_gpc = off’ at the bottom (regardless of whether they’ve been set earlier in the file). I also set:
[PHP]
max_execution_time = 60
max_input_time = 90
memory_limit = 64M
post_max_size = 32M
upload_max_filesize = 31M
magic_quotes_gpc = Off
Finally add the below line to your web-root htaccess file, to make the local php.ini the web-root default (so you don’t need a copy in every script sub-folder):
SetEnv PHPRC /home/LinuxPackage/public_html/php.ini
Hope that helps a few people save some time!
P.S. Using the new php_ini_loaded_file() function the whole lot could be done in three lines:
exec(«cp » . php_ini_loaded_file() . » » . $_SERVER[‘DOCUMENT_ROOT’] . «/php.ini»);
fwrite(fopen(«/php.ini», ‘a’), PHP_EOL . ‘[PHP]’ . PHP_EOL . «magic_quotes_gpc = Off» . PHP_EOL);
fwrite(fopen(«/.htaccess», ‘a’), PHP_EOL . «SetEnv PHPRC /php.ini» . PHP_EOL);
14 years ago
if ( get_magic_quotes_gpc ()) function stripslashes_gpc (& $value )
$value = stripslashes ( $value );
>
array_walk_recursive ( $_GET , ‘stripslashes_gpc’ );
array_walk_recursive ( $_POST , ‘stripslashes_gpc’ );
array_walk_recursive ( $_COOKIE , ‘stripslashes_gpc’ );
array_walk_recursive ( $_REQUEST , ‘stripslashes_gpc’ );
>
?>
5 years ago
Mike’s answer worked for me. The only thing that was different was finding the path to the php.ini file.
Configuration File (php.ini) Path said the path was /etc, but this wasn’t true. There was no php.ini there.
To find the path, I had to type
php -i | grep /php.ini
in the terminal. This gave the correct path, which was /opt/php70/lib/php.ini
16 years ago
PHP’s magic quotes function has the strange behavior of not adding slashes to top level keys in GPC key/value pairs but adding the slashes in deeper level keys. To demonstrate, a URI of:
example.php?a’b[c’d]=e’f
produces:
array(«a’b» => array(«c\’d» => «e\’f»))
The current example for removing magic quotes does not do anything to keys, so after running stripslashes_deep, you would end up with:
array(«a’b» => array(«c\’d» => «e’f»))
Which, needless to say, is wrong. As if you had magic quotes off, it would have been:
array(«a’b» => array(«c’d» => «e’f»))
I have written a snippet of code compatible with PHP 4.0.0 and above that handles this correctly:
if (get_magic_quotes_gpc()) function undoMagicQuotes($array, $topLevel=true) $newArray = array();
foreach($array as $key => $value) if (!$topLevel) $key = stripslashes($key);
>
if (is_array($value)) $newArray[$key] = undoMagicQuotes($value, false);
>
else $newArray[$key] = stripslashes($value);
>
>
return $newArray;
>
$_GET = undoMagicQuotes($_GET);
$_POST = undoMagicQuotes($_POST);
$_COOKIE = undoMagicQuotes($_COOKIE);
$_REQUEST = undoMagicQuotes($_REQUEST);
>
17 years ago
The function parse_str() (http://us3.php.net/manual/en/function.parse-str.php) is also affected by magic_quotes_gpc, so if that function is called anywhere, stripslashes_deep won’t be sufficient by itself.
17 years ago
The function stripslashes_deep() ignores slashes in the keys
For example a query string like this: ?foo’bar=baz’bal
Output of var_dump($_GET) is:
If you want the keys to be stripslashed too, you have to unset() the addslahed key and to add a stripslashed version. But keep in mind that this will change the order of the array.
9 years ago
These instructions are great. And if you have a site with an integrated shopping cart, then you will need to copy PHP.ini from the root of your site to the root folder of your shopping cart — otherwise you will still get errors on your cart pages.
14 years ago
I have recently found out that magic quotes affects not only the values of the GPC arrays, but also the keys.
For now, my way to solve with the problem is:
if ( get_magic_quotes_gpc ()) function magicQuotes_awStripslashes (& $value , $key ) < $value = stripslashes ( $value );>
$gpc = array(& $_GET , & $_POST , & $_COOKIE , & $_REQUEST );
array_walk_recursive ( $gpc , ‘magicQuotes_awStripslashes’ );
>
?>
Unfortunately it doesn’t fix the keys. and cannot determinate if the slashes are already stripped.
9 years ago
i do not check for get_magic_quotes_gpc is on of off as we should remove all slashes. another thing is to remove slashes using strip slash will only remove «\» to «» and «\\» to «\»
To over come this problem i use str_replace(array( ‘\\’), », $v)
Update Example 2
$process = array(& $_GET , & $_POST , & $_COOKIE , & $_REQUEST );
while (list( $key , $val ) = each ( $process )) foreach ( $val as $k => $v ) unset( $process [ $key ][ $k ]);
if ( is_array ( $v )) $process [ $key ][ str_replace (array( ‘\\’ ), » , $k )] = $v ;
$process [] = & $process [ $key ][ str_replace (array( ‘\\’ ), » , $k )];
> else $process [ $key ][ str_replace (array( ‘\\’ ), » , $k )] = str_replace (array( ‘\\’ ), » , $v );
>
>
>
unset( $process );
- Волшебные кавычки
- Что такое волшебные кавычки?
- Зачем мы использовали волшебные кавычки?
- Почему не надо использовать волшебные кавычки
- Отключение волшебных кавычек
- Copyright © 2001-2023 The PHP Group
- My PHP.net
- Contact
- Other PHP.net sites
- Mirror sites
- Privacy policy
Почему вместо » отображается & quot;?
Привет всем!
Купил прикольный скрипт микроблога на кодконьене, так вот проблемка в нем.
При добавлении сообщения на сайт (поста), вместо кавычек, на сайте показывается » & quot;».по принципу "новичкам везет" — перв
Почему и как исправить?
Вот файл настроек, может подскажите где поправить это:$icon $message x
