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 » Thu Oct 02, 2003 9:02 am
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?
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Thu Oct 02, 2003 9:33 am
maybe because you have the arguements the wrong way around....
Code: Select all
$line = str_replace(rawurlencode("'"),rawurlencode(" "),$line);
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Thu Oct 02, 2003 9:39 am
no...still echoes as
apostrophe''s .
Cheers anyway though.
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Thu Oct 02, 2003 9:44 am
Why use rawurlencode in the first place?
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Thu Oct 02, 2003 9:47 am
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?
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Thu Oct 02, 2003 9:55 am
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);
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Thu Oct 02, 2003 10:35 am
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
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Oct 07, 2003 4:42 am
what are magic_quotes_gpc and magic_quotes_runtime set to on your system?
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Oct 07, 2003 4:43 am
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Tue Oct 07, 2003 6:20 pm