我想从我的内容(如@img::56 )中获得价值
@img::56 => value=56从数据数据库mysql_query("select * from tblgallery where g_id=56");获取记录。
塔拉吴哥酒店是第一个四星级豪华酒店建造在神秘的土地吴哥。@youtube::https://www.youtube.com/watch?v=k4YRWT @img:塔拉吴哥窟酒店地理位置优越,地理位置优越,距离吴哥窟世界遗产遗址仅6公里,距暹粒国际机场15分钟车程,步行几分钟即可到达吴哥国家博物馆和@img:41,短途可到达市中心,提供一系列柬埔寨纪念品、购物和文化。
我想得到结果
塔拉吴哥酒店是第一个四星级豪华酒店建造在神秘的土地吴哥。mysql_query("select * from tblgallery g_id=56") 地理位置优越,距离吴哥窟世界遗产遗址吴哥窟仅6公里,距暹粒国际机场15分钟车程,步行几分钟即可到达吴哥窟国家博物馆和mysql_query(“从泰布尔美术馆选择*在那里”)短途车程到达城市中心,提供一系列柬埔寨纪念品、购物和文化。
发布于 2014-12-05 17:26:43
如果我理解你的问题,你想从字符串@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作为整数,则可以使用(int) $components[1]进行类型转换。
希望这能有所帮助。
https://stackoverflow.com/questions/27321216
复制相似问题