gpt4 book ai didi

PHP Preg 匹配 - 获取包装值

转载 作者:可可西里 更新时间:2023-11-01 00:13:17 24 4
gpt4 key购买 nike

我想使用预匹配提取所有换行的文本值

所以

background: url("images/gone.png");
color: #333;
...

background: url("images/good.png");
font-weight: bold;

从上面的字符串,我要抢

images/gone.png
images/good.png

正确的命令行是什么?

最佳答案

在 php 中,你应该这样做:

$str = <<<CSS
background: url("images/gone.png");
color: #333;

background: url("images/good.png");
font-weight: bold;
CSS;

preg_match_all('/url\("(.*?)"\)/', $str, $matches);
var_dump($matches);

然后,你会看到这样的输出:

array(2) {
[0]=>
array(2) {
[0]=>
string(22) "url("images/gone.png")"
[1]=>
string(22) "url("images/good.png")"
}
[1]=>
array(2) {
[0]=>
string(15) "images/gone.png"
[1]=>
string(15) "images/good.png"
}
}

因此,带有 url 的列表将位于 $matches[1] :)

关于PHP Preg 匹配 - 获取包装值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431926/

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