Regex & PHP - isolate src attribute from img tag

前端 未结 10 1428
眼角桃花
眼角桃花 2020-11-28 08:55

With PHP, how can I isolate the contents of the src attribute from $foo? The end result I\'m looking for would give me just \"http://example.com/img/image.jpg\"



        
10条回答
  •  醉梦人生
    2020-11-28 09:49

    Here's what I ended up doing, although I'm not sure about how efficient this is:

    $imgsplit = explode('"',$data);
    foreach ($imgsplit as $item) {
        if (strpos($item, 'http') !== FALSE) {
            $image = $item;
            break;
        }
    }
    

提交回复
热议问题