crawlerbasher Posted January 14, 2010 Share Posted January 14, 2010 I'm getting this error message and can't understand why its empty. Warning: eregi_replace() [function.eregi-replace]: REG_EMPTY in /home/cra10002/public_html/mooglebook/function.php on line 72 The database has 4 values in it and yet it says its empty. I've checked the spelling of the tables and database name to make sure that there match, and there do. There is no problem conection to the database as there is no error message been produce saying other wise. This is the code, that I'm using to try and get the word replaced with another word. <?php function badword($txt) { require("config.php"); $con = mysql_connect($db_server, $db_username, $db_password); // Connects to your database if (!$con) { die('Could not connect: ' . mysql_error()); // error message when failed to connect. } mysql_select_db($db_name) or die(mysql_error()); $result = mysql_query("SELECT COUNT(*) FROM Moogle_Book_Badword"); while($data = mysql_fetch_assoc($result)) { $txt = eregi_replace($data['bad_word'],$data['replaced_word '], $txt); } return $txt; } ?> Line 72 is where it starts of with $txt So what am I doing wrong here? Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/ Share on other sites More sharing options...
JAY6390 Posted January 14, 2010 Share Posted January 14, 2010 before this line $txt = eregi_replace($data['bad_word'],$data['replaced_word '], $txt); put echo '<pre>'.print_r($data, true).'</pre>'; When you then run it, does it show any data? Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995185 Share on other sites More sharing options...
crawlerbasher Posted January 14, 2010 Author Share Posted January 14, 2010 it did not. But I moved the fucntion to the top first. and that fixed the none text kind of. And found the problem. I should have used $result = mysql_query("SELECT * FROM Moogle_Book_Badword"); And not COUNT(*) The current problem at the moment is, it removes the bad word, but dose not replace it with the new word, instead the word is blank. ie Badword this rabbit. out put is This rabbit. Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995190 Share on other sites More sharing options...
JAY6390 Posted January 14, 2010 Share Posted January 14, 2010 Just so you are aware, you want to steer clear of eregi. It's deprecated as of php v 5.3.0 and isn't in PHP6. You should use the preg functions instead (preg_replace() in this instance). as for the word, you have a space in the key for the second value ['replaced_word '] should be ['replaced_word'] Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995194 Share on other sites More sharing options...
crawlerbasher Posted January 14, 2010 Author Share Posted January 14, 2010 got it now. The last error I made was a space before the ' Thank you for the help. Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995199 Share on other sites More sharing options...
crawlerbasher Posted January 14, 2010 Author Share Posted January 14, 2010 would this code help me with the problem of an REG_EMPTY error when there is notthing in the database? <?php function badword($txt) { require("config.php"); $con = mysql_connect($db_server, $db_username, $db_password); // Connects to your database if (!$con) { die('Could not connect: ' . mysql_error()); // error message when failed to connect. } mysql_select_db($db_name) or die(mysql_error()); $result = mysql_query("SELECT * FROM Moogle_Book_Badword"); while($data = mysql_fetch_assoc($result)) { if ($data['bad_word'] && $data['replaced_word']) { $txt = eregi_replace($data['bad_word'], $data['replaced_word'], $txt); } } } return $txt; } ?> Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995203 Share on other sites More sharing options...
JAY6390 Posted January 14, 2010 Share Posted January 14, 2010 In what way exactly would you want it to help Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995206 Share on other sites More sharing options...
crawlerbasher Posted January 14, 2010 Author Share Posted January 14, 2010 when the database is empty it will procude the REG_EMPTY error message. Would the new script prevent that from happening if there was no information in the database? Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995212 Share on other sites More sharing options...
JAY6390 Posted January 14, 2010 Share Posted January 14, 2010 after the mysql_query line put if(!mysql_num_rows($result)) return false; Link to comment https://forums.phpfreaks.com/topic/188502-reg_empty/#findComment-995215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.