Jump to content

[SOLVED] Replacing SMART quotes


Recommended Posts

<?
$p=$_POST['p'];
if ($_POST['p']){
$p=str_replace("“", "\"", $p);
$p=str_replace("”", "\"", $p);
$p=str_replace("’", "'", $p);
$p=str_replace("‘", "'", $p);
$p=str_replace("–", "-", $p);
$p=str_replace("•", "-", $p);
}?>

<table width="100%"><tr><td class="left"><div id="gg"><?echo "$p";?></div></td></tr></table><br><br>
<form method="POST" name="ff">
<textarea style="width:60%;height:400px;" name="p"></textarea>
<br><input type="submit" value="Go">
</form>

 

My code is as simple as that but str_replace isn't changing them. Thats ALL the HTML and PHP on my page I've stripped away any other things that could cause it. Thats all on my page. Why aren't things changing?

Link to comment
Share on other sites

because

if ($_POST['p'])

isn't ever true.

 

it should be

if (isset($_POST['p']) && !empty($_POST['p']))

 

but actually you should call that FIRST


if (isset($_POST['p']) && !empty($_POST['p'])){
$p=$_POST['p'];
$p=str_replace("“", "\"", $p);
$p=str_replace("”", "\"", $p);
$p=str_replace("’", "'", $p);
$p=str_replace("‘", "'", $p);
$p=str_replace("–", "-", $p);
$p=str_replace("•", "-", $p);
}?>

 

Link to comment
Share on other sites

If I add:

$p=str_replace("a", "gfdgfgfdg", $p);

to it it works just fine.

 

Nonetheless, I tried adding your bit but no, it does nothing. The characters aren't replaced.

 

 

Letters, numbers and simple punctuation don't seem to be a problem for str_replace to work but I can't get it to with those characters.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.