作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在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?
最佳答案
使用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]);
<?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/
我是一名优秀的程序员,十分优秀!