Page 1 of 2
dumb question
Posted: Thu Aug 02, 2007 4:18 pm
by webmeister
I am trying to construct a string such as
$str = "&x=7&y=12";
I need to send these characters out literally but php inserts a '#' between the & and the x.
if I output, it gives me this:
&#x=7&y=12
how do I fix this?
Thanks
Posted: Thu Aug 02, 2007 4:24 pm
by John Cartwright
Show code please.
Posted: Thu Aug 02, 2007 4:27 pm
by RobertGonzalez
Moved to PHP Code.
Posted: Thu Aug 02, 2007 4:34 pm
by webmeister
Jcart wrote:Show code please.
I thought I already did.
If I make a string such as this:
$str = "&x=7&y=12";
and I echo it back ie:
echo $str;
The output I get is:
&#x=7&y=12
Php is putting a '#' in between the '&' and the 'x'
I am new to php; my experience is in C
Is there some kind of an escape sequence to fix this or is it a bug in php?
Posted: Thu Aug 02, 2007 4:45 pm
by RobertGonzalez
Perhaps I can clarify what Jcart was asking...
Post the code that you are actually running, not the one line that you are having problems with. There could be any number of things taking place. Unless of course your entire PHP app is
Code: Select all
<?php
$str = "&x=7&y=12";
echo $str;
?>
in which case I really couldn't tell you what is up.
To better help us help you though, please run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
Posted: Thu Aug 02, 2007 5:02 pm
by webmeister
Everah wrote:Perhaps I can clarify what Jcart was asking...
Post the code that you are actually running, not the one line that you are having problems with. There could be any number of things taking place. Unless of course your entire PHP app is
Code: Select all
<?php
$str = "&x=7&y=12";
echo $str;
?>
in which case I really couldn't tell you what is up.
To better help us help you though, please run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
I just left a sniplet because I think that should be enough.
I get this from your source:
PHP Version: 4.4.7
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: /usr/local/Zend/etc/php.ini
Loaded Extensions:
zip xmlrpc xml tokenizer
standard sockets session pspell
posix overload mysql mhash
mcrypt mbstring gettext gd
ftp exif domxml curl
ctype calendar bcmath zlib
pcre openssl apache ffmpeg
suhosin Zend Optimizer
Posted: Thu Aug 02, 2007 5:05 pm
by pickle
webmeister wrote:I just left a sniplet because I think that should be enough.
Well it's not - that's why we've asked for more.
Try dropping the double quotes for single quotes.
Posted: Thu Aug 02, 2007 5:34 pm
by webmeister
pickle wrote:webmeister wrote:I just left a sniplet because I think that should be enough.
Well it's not - that's why we've asked for more.
Try dropping the double quotes for single quotes.
I found out that the problem isn't php; it is my netscape browser! If I use internet explorer, it comes back correct; if I use netscape it inserts a # between the & and the x; I don't know why.....do you?
Posted: Thu Aug 02, 2007 5:37 pm
by RobertGonzalez
webmeister wrote:I just left a sniplet because I think that should be enough.
Little snippets are never enough. That's why we ask for more.
Try this:
And post back what is echo'ed.
Posted: Thu Aug 02, 2007 5:38 pm
by RobertGonzalez
webmeister wrote:I found out that the problem isn't php; it is my netscape browser! If I use internet explorer, it comes back correct; if I use netscape it inserts a # between the & and the x; I don't know why.....do you?
What version of the Netscape browsers are you using? What is the character set encoding on the markup that is being sent to the browser?
Posted: Thu Aug 02, 2007 5:47 pm
by webmeister
Everah wrote:webmeister wrote:I just left a sniplet because I think that should be enough.
Little snippets are never enough. That's why we ask for more.
Try this:
And post back what is echo'ed.
netscape 7.2 using view source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
&#x=7&y=12
</body>
</html>
Posted: Thu Aug 02, 2007 6:00 pm
by RobertGonzalez
Now t try this and see what comes of it:
Code: Select all
<?php
echo '&x=7&y=12';
echo '<br />';
echo urlencode('&x=7&y=12');
?>
Posted: Thu Aug 02, 2007 6:01 pm
by webmeister
I also used a network sniffer so I know the php is sending what it's supposed to. I guess netscape inserts the '#' between the '&' and a 'x'; I just don't understand why. Must be a netscape thing!
Posted: Thu Aug 02, 2007 6:02 pm
by webmeister
Everah wrote:Now t try this and see what comes of it:
Code: Select all
<?php
echo '&x=7&y=12';
echo '<br />';
echo urlencode('&x=7&y=12');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
&x=7&y=12<br />%26x%3D7%26y%3D12
</body>
</html>
Posted: Thu Aug 02, 2007 6:09 pm
by VladSun
webmeister wrote:I also used a network sniffer so I know the php is sending what it's supposed to. I guess netscape inserts the '#' between the '&' and a 'x'; I just don't understand why. Must be a netscape thing!
Maybe because & is special symbol - it marks the begining of HTML entity. And a hex value HTML entity looks like:
1 (that is for '1')