<?php
$str = <<<str
    <img src="1.jpg"/>
    <p>123123</p>
    <span>3322</span>
    <img src="https://www.baidu.com/2.png" alt="">
    <img src="https://www.baidu.com/2.jpeg" alt="">
    <img src="https://www.baidu.com/2.bmp" alt="">
    <img src="https://www.baidu.com/2.bmp" alt="">
    <img src='https://www.baidu.com/2.bmp' alt="">
str;

preg_match_all( '~<img.*?src=["\']+(.*?)["\']+~' , $str, $match );

p($match['1']);

/**Array
(
    [0] => 1.jpg
    [1] => https://www.baidu.com/2.png
    [2] => https://www.baidu.com/2.jpeg
    [3] => https://www.baidu.com/2.bmp
    [4] => https://www.baidu.com/2.bmp
    [5] => https://www.baidu.com/2.bmp
)
**/

function p($var)
{
    if (is_bool($var)) {
        var_dump($var);
    } else if (is_null($var)) {
        var_dump(NULL);
    } else {
        echo "<pre style='position:relative;z-index:1000;padding:10px;border-radius:5px;background:#F5F5F5;border:1px solid #aaa;font-size:14px;line-height:18px;opacity:0.9;'>" . print_r($var, true) . "</pre>";
    }
}

php使用生成器读取超大文件

<?php function getLines($file) { $f = fopen($file, 'r'); try { while ($line = fgets($f)) { yield $line; ...

阅读全文

php获取字符串里面的图片,xpath方式

代码 <?php $html = <<<str <html> <head> <title>123</title> </head> <body> <img src=&quo...

阅读全文

Thinkphp5 in查询结果按照in里面的顺序排

或许有人会注意过,但我以前真不知道 SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序...

阅读全文

欢迎留言