rubing Posted February 10, 2008 Share Posted February 10, 2008 I am using php to read in a text file that is going to get inserted into my database. Before insertion I do some minimal processing. One of the things I want to do is replace this funny little character block: Â’ with just a good ol fashioned single quote: ' For some reason though it does not detect this entity so I am currently doing it with my text proccessor. $pattern3='/Â’/'; $replacement3 = '\''; $band2 = preg_replace($pattern3,$replacement3,$band2); $venue = preg_replace($pattern3,$replacement3,$venue); Quote Link to comment Share on other sites More sharing options...
rubing Posted February 10, 2008 Author Share Posted February 10, 2008 I attempted to fix this by changing my character encoding to UTF-8. Now, this character doesn't even get processed...it's like it isn't there at all. I guess that's better than having ? all over. Still, I'd like to get a single quote back! Quote Link to comment Share on other sites More sharing options...
effigy Posted February 11, 2008 Share Posted February 11, 2008 You're suffering from a "smart quote." These range from 0x91-0x94 in the Windows-1252 encoding. You can fix the UTF-8 document with $str = preg_replace('/[\x91\x92]/u', "'", $str); $str = preg_replace('/[\x93\x94]/u', '"', $str); Quote Link to comment Share on other sites More sharing options...
rubing Posted February 12, 2008 Author Share Posted February 12, 2008 This is super strange. When I issue the command to eliminate the smart quote the whole record just disappears from my table! Moreover the same thing happens if I use a notebook to do a search and replace for: Â’ I am completely stumped here!! ??? ??? Quote Link to comment Share on other sites More sharing options...
rubing Posted February 12, 2008 Author Share Posted February 12, 2008 That should read: from my html table. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2008 Share Posted February 12, 2008 Please provide the relevant code and data. Quote Link to comment Share on other sites More sharing options...
rubing Posted February 12, 2008 Author Share Posted February 12, 2008 Sure... here is an example of some of my data from the textfile i am processing: Thursday, 2/7 Chris Keenan Back Nine: CheemoÂ’s Creation BaileyÂ’s: Eric Mcginty Barking Kudu: Lettin Go Live BillyÂ’s: Fiery Furnaces/Lonesome Spirit Device Bottletree: And now here is the code i am using to process it: <?php include '../../lib/config.inc'; include '../../lib/opendb.inc'; $lines = file("source.txt"); foreach($lines as $single_line) { $value_arr = explode("\t", $single_line); if (empty($value_arr[0])) //if the first column is empty { $DATE = $value_arr[1] ; //assigns the date in the second column variable $DATE } $newline = "<br />"; //for formatting html output later on $var1=$value_arr[0]; //this is the band $var2=$value_arr[1]; //this is the venue $vara=html_entity_decode($var1); //converts stupid html in band $varb=html_entity_decode($var2); //converts dumb html in venue $band = trim($vara,", "); //trims space and comma from front and back $venue = trim($varb,":, "); //trims all that and colon at end $band = trim($band, " "); //trim extra space? untested, added 2/9/08 $venue = trim($venue, " "); if ($band != $DATE) //do not insert double date records { $timestamp1= strtotime($DATE); $date = date("Y-m-d", $timestamp1); // replace w/, with $pattern = '/w\//'; $replacement = 'with '; $band2 = preg_replace($pattern,$replacement,$band); //replace smart quote with dumb one $band2 = preg_replace('/[\x91\x92]/u', "'", $band2); $venue = preg_replace('/[\x91\x92]/u', "'", $venue); echo ereg_replace( ' +', '', $band2 ); echo ereg_replace( ' +', '', $venue ); //trims double space //split the band arrays up $bandarray = split('[/,]',$band2); foreach($bandarray as $band3) { $source = "bw"; // trying to delete first new code follows $band4=substr($band3, 0, 3); $venue4=substr($venue,0, 3); echo $newline; echo "$band4 | $venue4 | $date"; $deliciousquery="DELETE FROM MusicEvents WHERE (Left(Band,3)='$band4' AND Left(Venue,3)='$venue4' AND Date='$date')"; mysql_query($deliciousquery); if (!empty($band3)) //if the first column band is not empty { $query = "INSERT INTO MusicEvents (Source, Band, Venue, Date) VALUES ('$source','$band3', '$venue','$date')"; mysql_query($query); // echo $band3 . "," . $venue . "," . $date, $newline; } } } } mysql_close($conn); ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2008 Share Posted February 12, 2008 It works for me if I comment out the includes and querying. I would place an echo after each step to see where it goes astray. Quote Link to comment Share on other sites More sharing options...
rubing Posted February 12, 2008 Author Share Posted February 12, 2008 Yes, I can get it to work and replace the smart quote with a dumb one, but for some reason thereafter these entries with the replaced quote will not be selected when i issue a mysql query. strange Quote Link to comment Share on other sites More sharing options...
rubing Posted February 13, 2008 Author Share Posted February 13, 2008 Correction. These entries are not being inserted in my mysql table (I was looking at another type of smart quote that was inserted) However, they echo just fine before insertion. I wonder why these entries can't be inserted ??? Maybe I should post this to the mysql board Quote Link to comment Share on other sites More sharing options...
rubing Posted February 13, 2008 Author Share Posted February 13, 2008 OK, I hacked out a solution, which has me satisfied. Instead of doing the find and replace in php, I just issue the command directly to mysql. Works fine. UPDATE MusicEvents SET Venue = replace( Venue, 'Â’', '\'' ) ; Quote Link to comment Share on other sites More sharing options...
effigy Posted February 13, 2008 Share Posted February 13, 2008 All inserts should be passed through mysql_real_escape_string. Quote Link to comment Share on other sites More sharing options...
rubing Posted February 13, 2008 Author Share Posted February 13, 2008 OH of Course! I forgot that I was passing a single quote and that may wreak havoc! Thanks effigy you're a real pro! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.