...

View Full Version : preg_replace causing to repeat



gilgalbiblewhee
07-16-2008, 05:39 AM
I think the preg_replace is causing the former result to repeat:

INSERT INTO correction_nbsp (bwas_pages_id, content_before, content_after) VALUES (702, 'chapter: ', ' CHAPTER 1 chapter: ')
INSERT INTO correction_nbsp (bwas_pages_id, content_before, content_after) VALUES (711, 'copies &nbspfrom &nbspauthoritative &nbspsources &nbspshowing &nbspthe ', ' CHAPTER 1 chapter: copies from authoritative sources showing the ')
INSERT INTO correction_nbsp (bwas_pages_id, content_before, content_after) VALUES (714, 'told what the truth is, and still not see it. ', ' CHAPTER 1 chapter: copies from authoritative sources showing the told what the truth is, and still not see it. ')
INSERT INTO correction_nbsp (bwas_pages_id, content_before, content_after) VALUES (716, 'see it? ', ' CHAPTER 1 chapter: copies from authoritative sources showing the told what the truth is, and still not see it. see it? ')

while($row = mysql_fetch_array($result)){
$old = preg_replace('#&?nbsp;?#i', ' ', $row['content']);
$new .= preg_replace("/[^ -þ]/", "", $old);
$sql_record2 = "INSERT INTO correction_nbsp (".$acronym."_pages_id, content_before, content_after)
VALUES (".$row['id'].", '".$row['content']."', '".$new."')";
mysql_query($sql_record2,$con) or die(mysql_error());
echo $sql_record2."<br />\n";
}

shyam
07-16-2008, 06:51 PM
I think the preg_replace is causing the former result to repeat:


while($row = mysql_fetch_array($result)){
$old = preg_replace('#&?nbsp;?#i', ' ', $row['content']);
$new .= preg_replace("/[^ -]/", "", $old);
$sql_record2 = "INSERT INTO correction_nbsp (".$acronym."_pages_id, content_before, content_after)
VALUES (".$row['id'].", '".$row['content']."', '".$new."')";
mysql_query($sql_record2,$con) or die(mysql_error());
echo $sql_record2."<br />\n";
}

preg_replace isn't doing that ur concatenating it each time


$new = preg_replace("/[^ -]/", "", $old);

just use this and you should be fine

gilgalbiblewhee
07-16-2008, 06:54 PM
Yes the .= should be taken out. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum