我需要从容器内的所有图像中获取所有源值。我在这方面遇到了一些困难。
请允许我解释一下这个过程。所有数据都来自一个数据库。在后台界面中,用户在文本区域中输入所有文本和图像。要将文本与图像分开,用户必须输入分页符。让我们转到代码
while ($rowClients = mysql_fetch_array($rsClients)) {
$result = $rowClients['content'];
$resultExplode = explode('<!-- pagebreak -->', $result);
// with resultExplode[0] I get the code and with resultExplde[1] I get the image
// Now with I want to get only the src value from resultExplode[1]
我已经试用过strip_tags
$imageSrc = strip_tags($resultadoExplode[1]);
但它什么也没印。
我找到了这个职位,但没有成功。我在第一次打印时停了下来。
有人能帮我吗??
感谢
如果无法打印出来,请尝试foreach。。(如果有问题的话)
foreach($resultExplode as $key => $value){
echo "[".$key."]".$value;
}
我找到了一个解决方案:
继续前面的代码,我使用split函数。
所以我开始剥去标签。通过这种方式,我将img与其他部分隔离。
$image = strip_tags($resultExplode[1],"<img>");
因为所有img都有相同的结构,如下所示:<img width="111" height="28" alt="alternative text" src="/path/to/the/file.png" title="title of the image">
我用"作为分隔符来分割这个字符串
$imgSplit = split('"', $image);
$src = $imgSplit[3];
Voilá。正在工作
你觉得这个程序怎么样??