public function unprefixResourceUrls($prefix) { foreach (phpQuery::pq('a, img', $this->doc) as $node) { HtmlUtils::unprefixNodeAttrs($node, 'src,href,srcset', $prefix, function ($url) { return Utils::isResourceUrl($url); }); } }
function test_unprefixNodeAttrs() { $doc = phpQuery::newDocument('<img src="p1/img0.jpg" srcset="p1/img1.jpg 1000w, img2.jpg" href="link.html"/>'); $img = phpQuery::pq('img', $doc)->elements[0]; $img = HtmlUtils::unprefixNodeAttrs($img, 'src, srcset,href,dummy', 'p1/'); $this->assertEquals('img0.jpg', $img->getAttribute('src')); $this->assertEquals('img1.jpg 1000w, img2.jpg', $img->getAttribute('srcset')); $this->assertEquals('link.html', $img->getAttribute('href')); }