2014-12-05 50 views
0

查找我想從我的內容中獲取價值,如@img::56如何獲得爆炸@img ::值在我的數據庫

@img::56 => value=56mysql_query("select * from tblgallery where g_id=56");於數據庫獲取記錄。

塔拉吳哥酒店是第一家建在吳哥神祕土地上的四星級豪華酒店。 @img :: 56理想情況下,@ youtube:https://www.youtube.com/watch?v=k4YRWT_Aldo塔拉吳哥酒店地理位置優越,距離世界遺產吳哥窟寺廟僅6公里,距離暹粒國際機場15分鐘車程,幾分鐘漫步到吳哥國家博物館和@img :: 41一小段車程到市中心與柬埔寨紀念品,購物和文化陣列。

我想導致

塔拉吳哥酒店是建於吳哥的神祕土地的第一個四星級的豪華酒店。 mysql_query(「select * from tblgallery where g_id = 56」)理想情況下,< iframe width =「560」height =「315」src =「// www.youtube.com/embed/k4YRWT_Aldo」frameborder =「0」 allowfullscreen > </iframe >位於交通便利的Tara Angkor Hotel酒店距離世界遺產吳哥窟寺廟僅6公里,距離暹粒國際機場15分鐘車程,距離吳哥國家博物館數分鐘步行路程,距離mysql_query (「select * from tblgallery where g_id = 41」)搭乘一系列柬埔寨紀念品,購物和文化,乘車前往市中心。

+0

而且......你的代碼是......? – 2014-12-05 17:14:52

+1

(提示:['preg_replace_callback'](http://php.net/preg-replace-callback)可能是你需要的工具) – 2014-12-05 17:15:22

+0

(你不需要在這裏使用HTML實體來顯示HTML - 只需粘貼你的HTML到框中,選中它並點擊代碼按鈕)。 – halfer 2014-12-05 17:17:57

回答

0

如果我理解你的問題,你想從字符串@img::56檢索56?

如果是這樣,它可以做到如下。

$string = '@img::56'; 

// Explode the string as the delimiter. 
$components = explode('::', $string); 

// Ensure the components array has two elements. 
if(count($components) < 2) { 

    // Do something here to indicate an error has occurred. 
    //Throw an exception (preferred) or emit an error 

} 

$id = $components[1]; 

// You can use even more type checking here to ensure you have the right piece of data. 
if(!ctype_digit($id)) { 

    //Throw an exception (preferred) or emit an error 

} 

// Accessing the database using a PDO object and prepared statements 

$pdo = new \PDO('mysql:host=...', 'username', 'password') 

$statement = $pdo->prepare('SELECT * FROM tblgallary WHERE g_id = :id'); 

$statement->bindParam(':id', $id, \PDO::PARAM_INT); 

if(!$statement->execute()) { 

    //Throw an exception (preferred) or emit an error 

} 

$result = $statement->fetchAll(\PDO::FETCH_ASSOC); 

// End the database connection 
$pdo = null; 

現在你已經有了id。如果你需要$id是一個整數,你可以用(int) $components[1]來代替它。

希望這會有所幫助。