preg_replace and database

From: Date: Sat, 19 Feb 2005 22:52:02 +0000
Subject: preg_replace and database
Groups: php.db 
Request: Send a blank email to php-db+get-38616@lists.php.net to get a copy of this message
hi all, I have trouble with preg_replace and querying database, my code is below, <?php include("h/h.php"); function getImgAttributes($id){ $dsn = array( 'phptype' => "mysql",
	    'hostspec' => "localhost",
	    'database' => "db",
	    'username' => "root",
	    'password' => "pass"
); $myDbc = DB::connect($dsn); $myDbc->setFetchMode(DB_FETCHMODE_ASSOC); $select_sql="select width, height, name from files where id='$id'"; $execute_query = $myDbc->query($select_sql); $row=$execute_query->fetchRow(); return 'id="'.$id.'" width="'.$row['width'].'" height="'.$row['height'].'" alt="'.$row['name'].'"'; } function writeImgTag ($text){ $search = '<img id="(.*?)" />'; $replace = 'div class="cimg"><img src="thumb.php?w=200&q=60&id=\1" '.getImgAttributes("\\1").' /></div'; $text = preg_replace ($search, $replace, $text); echo $text; } $text='<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec fermentum aliquam dolor.</p> <img id="433" /> <p>Pellentesque convallis, felis vel imperdiet tincidunt, urna augue porttitor leo, eu luctus elit ante non mi.</p>'; writeImgTag($text); ?> returns id but not DB result.... <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec fermentum aliquam dolor.</p> <div class="cimg"><img src="thumb.php?w=200&q=60&id=433" id="433" width="" height="" alt="" /></div> <p>Pellentesque convallis, felis vel imperdiet tincidunt, urna augue porttitor leo, eu luctus elit ante non mi.</p>

« previous php.db (#38616) next »