1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ellipses and apostrophes converted to question marks...

Discussion in 'PHP' started by jim_h, Mar 20, 2006.

  1. #1
    I run a php/mysql driven website and recently my host upgraded to PHP5. While all our scripts seem to run fine after the change, one thing I did notice is that some of the reviews are now showing tons of Question Marks in place of apostrophes and ellipses.
    The reviews this is affecting are those created in Microsoft Word beforehand and then pasted into a custom insert form for my MySQL database. The ones created in notepad don't seem to have this issue. Is there any fast way to resolve this or am I stuck manually editing them?
     
    jim_h, Mar 20, 2006 IP
  2. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't have a clean, easy way to do this. And I don't know why it worked on the earlier PHP installation but not your current one. If someone knows how to clean Microsoft smart quotes or can shed some light on this, please advise.

    Here's a article talking about it.
    http://ezinearticles.com/?Microsoft-Word-Smart-Quotes-and-Article-Marketers-Dont-Mix&id=15624

    Here's how I currently do it. I haven't worked on this code in a few years now but it has worked ok for me.

    $str is the code I want to clean. $out is what is returned. This snippet is designed to be in a function where you feed in $str and get back $out.

    
              //////////  Remove invalid characters.  -  if any exist.
    
              for ( $i = 0; $i < strlen($str); $i++ )
              {
    
                   $num = ord($str[$i]);
    
    
                   if (  ($num==10) || ($num==13) || (($num>=32)&&($num<=127)) || (($num>=145)&&($num<=148))  )
                   {
    
                        if ( ($num==145) || ($num==146) )
                        {
                             $out .= "'";
                        }
                        elseif ( ($num==147) || ($num==148) )
                        {
                             $out .= "\"";
                        }
                        else
                        {
                             $out .= chr($num);
                        }
                   }
                   else
                   {
                        //////////  Build array of characters removed to show user later.
    
                        $invalids[] = chr($num);
                   }
              }
    
    PHP:
     
    rvarcher, Mar 20, 2006 IP