Page 1 of 1
apostrophes
Posted: Mon Oct 06, 2003 5:46 am
by mesz
Code: Select all
<?php
$fp = fopen('./news.txt','a+');
if($HTTP_POST_VARS['submit'])
{
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news']. "|" . $HTTP_POST_VARS['poster'];
$line = str_replace("\r\n","<br>",$line);
$line = str_replace("'"," ",$line);
$line .= "\r\n";
fwrite($fp, $line);
}
?>
I am still and forever investigating this:
why can I not replace apostrophes properly?
No one, even on php.net has a reasonable answere to this infinite question.
Posted: Mon Oct 06, 2003 6:13 am
by volka
can't reproduce the error either but what does
Code: Select all
<?php
if($HTTP_POST_VARS['submit'])
{
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news']. "|" . $HTTP_POST_VARS['poster'];
$cc = count_chars ($line, 1);
echo 'before: ', $cc[39], '<br />';
$line = str_replace("\r\n","<br>",$line);
$line = str_replace("'"," ",$line);
$line .= "\r\n";
$cc = count_chars ($line, 1);
echo 'after: ', $cc[39];
}
?>
output?
Posted: Mon Oct 06, 2003 10:56 am
by tsg
Are you getting slashes in the replace? Probably .. add this line before the str_replace line:
Posted: Tue Oct 07, 2003 4:12 am
by mesz
cheers tsg - but it did not work:
script:
Code: Select all
<?php
$fp = fopen('./news.txt','a+');
if($HTTP_POST_VARS['submit'])
{
$line = stripslashes($line);
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news']. "|" . $HTTP_POST_VARS['poster'];
$line = str_replace("\r\n","<br>",$line);
$line = str_replace(rawurlencode("'"),rawurlencode(" \ \ "),$line);
$line .= "\r\n";
fwrite($fp, $line);
}
?>
Output:
another week - another test10.07.03
are there any apostrophe''s
posted by site admin
Posted: Tue Oct 07, 2003 4:22 am
by mesz
volka wrote:can't reproduce the error either but what does
Code: Select all
<?php
if($HTTP_POST_VARS['submit'])
{
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news']. "|" . $HTTP_POST_VARS['poster'];
$cc = count_chars ($line, 1);
echo 'before: ', $cc[39], '<br />';
$line = str_replace("\r\n","<br>",$line);
$line = str_replace("'"," ",$line);
$line .= "\r\n";
$cc = count_chars ($line, 1);
echo 'after: ', $cc[39];
}
?>
output?
This OUTPUTS:
on submit:
the words before and after are echoed to screen, and no output shown on view.php
Posted: Tue Oct 07, 2003 4:32 am
by mesz
This works:
Code: Select all
<?php
$fp = fopen('./news.txt','a+');
if($HTTP_POST_VARS['submit'])
{
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news']. "|" . $HTTP_POST_VARS['poster'];
$line = str_replace("\r\n","<br>",$line);
$line = stripslashes($line);
$line .= "\r\n";
fwrite($fp, $line);
}
?>