提问人:Mert Köksal 提问时间:7/4/2022 最后编辑:Mert Köksal 更新时间:7/4/2022 访问量:52
拆分数据库中的多个字符串
split multiple strings in database
问:
这是我第一次尝试这样的事情。我希望那些理解的人能提供帮助。
我正在尝试生成电子商务 XML,但在我的数据库中,通过这种方式,我将产品的所有图片保存到我的数据库中。但是我无法弄清楚如何用foreach结构将['this way','images']彼此区分开来。['https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/v1/l_20211-s1i862z8-hfm_a.jpg', 'https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/v1/l_20211-s1i862z8-hfm_a1.jpg', 'https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/l_20211-s1i862z8-hfm_a2.jpg', 'https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/l_20211-s1i862z8-hfm_a3.jpg']
我想要的是让他一张一张地拍照片。a [不完整]
例如:
图片 1:这是图片 URL。 图 2:字符串中的第二个图像 URL。
我怎样才能让它变成这样?
PHP代码:
<?php
$urunler = $baglanti->query("SELECT * FROM urunler LIMIT 50");
$urun = mysqli_fetch_array($urunler);
?>
<url>
<?php foreach ($urunler as $urun)
$urunlerx = $urun["image"];
{ ?>
<urunler>
<urunName><?php echo $urun["isim"]; ?></urunName>
<anaKategori><?php echo $urun["anakategori"]; ?></anaKategori>
<urunResim><?php echo $urun["image"]; ?></urunResim>
<urunKodu><?php echo $urun["kodu"]; ?></urunKodu>
<urunLink><?php echo $urun["link"]; ?></urunLink>
<normalFiyat><?php echo $urun["normalfiyat"]; ?></normalFiyat>
<urunEbat><?php echo $urun["ebatlar"]; ?></urunEbat>
<urunOzellik><?php echo $urun["ozellik"]; ?></urunOzellik>
<urunAciklama><?php echo $urun["aciklama"]; ?></urunAciklama>
</urunler>
<?php } ?>
</url>
</urlset>
答:
0赞
Markus Zeller
7/4/2022
#1
您可以使用正则表达式来查找单引号之间的所有字符串。
$data = <<<'_DATA'
['https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/v1/l_20211-s1i862z8-hfm_a.jpg', 'https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/v1/l_20211-s1i862z8-hfm_a1.jpg', 'https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/l_20211-s1i862z8-hfm_a2.jpg', 'https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/l_20211-s1i862z8-hfm_a3.jpg']
_DATA;
$matches = [];
preg_match_all("/'(.*?)'/", $data, $matches);
foreach($matches[1] as $url) {
echo "$url\n";
}
回声
https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/v1/l_20211-s1i862z8-hfm_a.jpg
https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/v1/l_20211-s1i862z8-hfm_a1.jpg
https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/l_20211-s1i862z8-hfm_a2.jpg
https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20211/5158707/l_20211-s1i862z8-hfm_a3.jpg
评论
$urunler
希望,如果查询工作 MYSQL::RESULT 对象,因此在提取 50 行中的一行时。但是使用它是无稽之谈,是行不通的。mysqli_fetch_array($urunler);
foreach ($urunler as $urun)