Jump to content

REG_EMPTY


crawlerbasher

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

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