Jump to content

preg_replace() does not replace: Â’


rubing

Recommended Posts

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);

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

This is super strange.  When I issue the command to eliminate the smart quote the whole record just disappears from my table!  :o

 

Moreover the same thing happens if I use a notebook to do a search and replace for: Â’

 

I am completely stumped here!! ??? ???

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.