Re: note 11756 added to eregi_replace

From: Date: Tue, 06 Mar 2001 06:23:30 +0000
Subject: Re: note 11756 added to eregi_replace
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-11922@lists.php.net to get a copy of this message
php@tb2.com writes: > shouldn't this work fine? > > while( > $row=mysql_fetch_object(eregi_replace('"',"&quot;",stripslashes($result))) > ) > { > ... You've got that inside out. You're attempting to pass mysql_fetch_object() the result of the eregi_replace(), which is a string. You should be passing it the result id of a previous query. It looks like the result id is getting passed to stripslashes() and hence on to eregi_replace(), which both expect strings; $result should be of type resource. Also, you don't need the processing power of eregi_replace() here; the case inconsistency applies only to strings to be matched--and since you're matching a set of double-quotes, for which there is no distinction between upper- and lower-case, it doesn't matter. And since you're just looking for a simple string, you can get by with the much faster str_replace(). And even better, since it looks like you're going for HTML entity conversions, I'd recommend htmlspecialchars() or htmlentities() to cope with it for you. Here's one way I'd probably write it--of course, you may be after something different, but this is just an example of how one guy would do it :). <?php error_reporting(E_ALL); $dbh = mysql_connect('host', 'user', 'password'); mysql_select_db('my_db_name'); $result = mysql_query('select * from my_table'); while ($row = mysql_fetch_array($result)) { foreach ($row as $key => $val) { $row[$key] = htmlspecialchars($val); } $rows[] = $row; } print_r($rows); ?> > it doesn't! instead i have to pick out certain $row->object's and > strisplash/eregi_replace them manually one at a time. there's gotta > be an easier way. > > http://www.php.net/manual/en/function.eregi-replace.php Hope this helps, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Adcore Finland| |http://www.coastnet.com/~torben http://www.adcore.com| |Ph: 1.604.709.0506 torben@adcore.com| +----------------------------------------------------------------+

« previous php.notes (#11922) next »