Author Topic: [SOLVED] Replacing SMART quotes  (Read 6131 times)

0 Members and 1 Guest are viewing this topic.

Offline PetsmackerTopic starter

  • Enthusiast
    • View Profile
[SOLVED] Replacing SMART quotes
« on: April 04, 2009, 04:00:38 AM »
Code: [Select]
<?
$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?
« Last Edit: April 04, 2009, 01:19:54 PM by zanus »

Online Zanus

  • Global Moderator
  • Fanatic
  • *
  • Gender: Male
  • dockeryz.com
    • View Profile
Re: Simple str_replace problem
« Reply #1 on: April 04, 2009, 04:08:42 AM »
because
Code: [Select]
if ($_POST['p']) isn't ever true.

it should be
Code: [Select]
if (isset($_POST['p']) && !empty($_POST['p']))
but actually  you should call that FIRST
Code: [Select]
<?
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);
}?>

Offline PetsmackerTopic starter

  • Enthusiast
    • View Profile
Re: Simple str_replace problem
« Reply #2 on: April 04, 2009, 04:15:15 AM »
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.

Offline kenrbnsn

  • PHPFreaks Recommended
  • Freak!
  • *
  • Gender: Male
    • View Profile
Re: Simple str_replace problem
« Reply #3 on: April 04, 2009, 10:23:38 AM »
What you are trying to do is replace "smart quotes" (dumb Microsoft quotes). Please read Convert Smart Quotes with PHP.

Ken

Offline PetsmackerTopic starter

  • Enthusiast
    • View Profile
Re: Simple str_replace problem
« Reply #4 on: April 04, 2009, 12:43:03 PM »
Legend. Thats solved the issue. Needless complications...

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.