dumb question
Moderator: General Moderators
-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
dumb question
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
$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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
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?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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
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.
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;
?>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;
}
?>-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
I just left a sniplet because I think that should be enough.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 isin which case I really couldn't tell you what is up.Code: Select all
<?php $str = "&x=7&y=12"; echo $str; ?>
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 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
-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
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?pickle wrote:Well it's not - that's why we've asked for more.webmeister wrote:I just left a sniplet because I think that should be enough.
Try dropping the double quotes for single quotes.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Little snippets are never enough. That's why we ask for more.webmeister wrote:I just left a sniplet because I think that should be enough.
Try this:
Code: Select all
<?php
echo '&x=7&y=12';
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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?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?
-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
Everah wrote:Little snippets are never enough. That's why we ask for more.webmeister wrote:I just left a sniplet because I think that should be enough.![]()
Try this:And post back what is echo'ed.Code: Select all
<?php echo '&x=7&y=12'; ?>
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>
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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');
?>-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
-
webmeister
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 02, 2007 4:11 pm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">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'); ?>
<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>
Maybe because & is special symbol - it marks the begining of HTML entity. And a hex value HTML entity looks like: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!
1 (that is for '1')
Last edited by VladSun on Thu Aug 02, 2007 6:27 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't