Page 1 of 1
str_replace rawurlencode apostrophes
Posted: Thu Oct 02, 2003 9:02 am
by mesz
Code: Select all
<?php
$line = str_replace("\r\n","<br>",$line);
$line = str_replace(rawurlencode(" "), rawurlencode("'"),$line);
?>
echoes like this - test''s
can anybody explain why I cannot correctly replace the apostrophes from a form upload code?
Posted: Thu Oct 02, 2003 9:33 am
by Wayne
maybe because you have the arguements the wrong way around....
Code: Select all
$line = str_replace(rawurlencode("'"),rawurlencode(" "),$line);
Posted: Thu Oct 02, 2003 9:39 am
by mesz
no...still echoes as
apostrophe''s .
Cheers anyway though.
Posted: Thu Oct 02, 2003 9:44 am
by JAM
Why use rawurlencode in the first place?
Posted: Thu Oct 02, 2003 9:47 am
by mesz
because I was using regular str_replace and my apostrophes were coming out as . . .
cat ' ' s
I read about str_replace on php manual and far down the page I found some advice about using rawurlencode for special characters...
I am prepared to admit I might have jumped on the wrong bandwagon, but what is the right one?
Posted: Thu Oct 02, 2003 9:55 am
by Wayne
if its just form data then you dont need the rawurlencode, but you still had the arguements. try ...
Code: Select all
$line = str_replace("'"," ",$line);
Posted: Thu Oct 02, 2003 10:35 am
by mesz
I have mashed my code to look like this:
view.php
Code: Select all
<?php
<?
$data = file('./news.txt');
$data = array_reverse($data);
foreach($data as $element) {
$ele = trim($ele);
$string = $pieces[3];
$pattern = array('!\[img\](.+?)\[/img\]!i', '!\[URL=(.*?)\](.*)\[/URL\]!i');
$replacement = array('<img src="\\1">', '<a class="whitearialsm" href="http://\\1">\\2</a>');
}
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
{
echo "<form class="form"><b>". $pieces[1] . "</b>" . $pieces[0]. "<br>" ;
echo $pieces[2] . "<br>" . "<small>posted by<i> ".$pieces[3] ."</i></small></form>" ;
}
}
?>
?>
and
addnews.php
Code: Select all
<?php
<?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);
}
?>
?>
however apostrophes still print incorrectly?
aghhhhhhhhhh
Posted: Tue Oct 07, 2003 4:22 am
by twigletmac
Why not just use
stripslashes()?
Mac
Posted: Tue Oct 07, 2003 4:42 am
by volka
what are magic_quotes_gpc and magic_quotes_runtime set to on your system?
Posted: Tue Oct 07, 2003 4:43 am
by mesz
Posted: Tue Oct 07, 2003 6:20 pm
by McGruff