gpt4 book ai didi

php - 如何从MySQL记录中获取图像文件名?

转载 作者:行者123 更新时间:2023-11-29 07:34:15 25 4
gpt4 key购买 nike

我在question_answers中有图像作为记录表。

图像存储<span style="font-family:'MS Reference Sans Serif'"><span style="font-size:9pt"><img width="51" height="32" align="bottom" alt="mc001-2.jpg" src="@@PLUGINFILE@@/mc001-2.jpg" border="0"></span></span>

如何获取图片名称mc001-2.jpg从这里使用 PHP 和 MySQL?

enter image description here

最佳答案

使用preg_match():-

<?php

$str = '<span style="font-family:MS Reference Sans Serif"><span style="font-size:9pt"><img width="51" height="32" align="bottom" alt="mc001-2.jpg" src="@@PLUGINFILE@@/mc001-2.jpg" border="0"></span></span>';
preg_match('/alt="(.*?)"/', $str, $out);

//see first output
echo ($out[1]);

输出:- https://eval.in/399769

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$conn = mysqli_query('server name','user name','password','database name') or die(mysqli_connect_error());
$query = mysqli_query($conn,"Select answer from question_answers") or die(mysqli_error($conn));
$img_name_array = array();
if(mysqli_num_rows($query) >0){

while ($row = mysqli_fetch_assoc($query)){
$image_data = $row['answer'];
preg_match('/alt="(.*?)"/',$str, $out);
$img_name_array[] = $out[1];
}

}else{

echo "no record exist";
}

注意:- $img_name_array 将包含所有图像名称。谢谢。

关于php - 如何从MySQL记录中获取图像文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31448554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com