apostrophes

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

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

apostrophes

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Are you getting slashes in the replace? Probably .. add this line before the str_replace line:

Code: Select all

$line = stripslashes($line);
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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); 
            } 
?>
Post Reply