PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Mon Oct 06, 2003 5:46 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Oct 06, 2003 6:13 am
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?
tsg
Forum Contributor
Posts: 142 Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:
Post
by tsg » Mon Oct 06, 2003 10:56 am
Are you getting slashes in the replace? Probably .. add this line before the str_replace line:
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Oct 07, 2003 4:12 am
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
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Oct 07, 2003 4:22 am
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
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Oct 07, 2003 4:32 am
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);
}
?>