skip to Main Content

Php – Extract all <a> and <img> tags (exactly as represented in the input) from HTML 5 that contain a specific class

I need to improve some open source code. It contains a function to extract all <a> and <img> tags with a specific class from a string that represents HTML. This function uses regular expressions: preg_match_all('#<img(.*)class="(.*)foo(.*)"(.*)>#Umsi', $text, $matches_img, PREG_PATTERN_ORDER); preg_match_all('#<a(.*)class="(.*)foo(.*)">(.*)</a>#Umsi', $text,…

VIEW QUESTION

Php – How to get value by id using DomDocument?

I am trying to get value of form below using DomDocument but so far still failed <?php $string ='<form action="profile" method="post" enctype="multipart/form-data"> <input type="hidden" name="id_user" id="id_user" value="123"> <input type="hidden" name="logo" id="logo" value="path/to/logo1.png"> <input type="hidden" name="status" id="status" value="Ok"> <input type="submit" value="PROFILE">…

VIEW QUESTION

Php – Select option from dropdown to be passed to variable and reload page with new domDocument

ok. have been fighting this for long now. I have following code that feches html from add site: $articleClassName = 'relative isolate sf-search-ad cursor-pointer overflow-hidden relative transition-all outline-none p-10 hover:bg-aqua-50 focus:bg-aqua-50 sf-search-ad-legendary -m-8'; $merchantID = '3553552'; $finn_link = 'https://www.addsite.tv/car/used/search.html?orgId='.$merchantID.'&sort='.$sortBy; $finnTagName…

VIEW QUESTION

Using DomDocument to Replace an <a> tag with Text – PHP

I'm looking to replace <a> tag in string with some text. My code is as follows $string = 'This link <a href="somedomain.com">Some Domain</a> needs to be removed'; $domdocument = new DOMDocument(); $domdocument->loadHTML($string, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $link = $domdocument->getElementsByTagName('a')[0]; $replacement_link =…

VIEW QUESTION
Back To Top
Search