我在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>
如何使用PHP和MySQL从这里获取图像名称mc001-2.jpg
?
答案 0 :(得分:2)
使用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
将包含所有图像名称。谢谢。
答案 1 :(得分:0)
SELECT image_name FROM question_answers
WHERE image_name LIKE '%mc001-2.jpg%';
如果我正确解释了您的问题,则意味着您将HTML存储在MySQL表中。我希望我错了。