preg_replace and database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux