Hiya! I just registered now. Can someone be kind enough to convert this code to procedural style php and past it here so I can learn the code aswell as all other newbies ? You see, I am still learning procedural style and have not gone to the oop level yet. It is a Link Extractor. <?php //Code from: https://potentpages.com/web-crawler-development/tutorials/php/techniques //Assuming your contents are in a variable called $contents //New DOM Document $document = new DOMDocument; //Load HTML in $contents variable $document->loadHTML($contents); //Get all links if($links = $document->getElementsByTagName('img')) { //Loop through all links foreach($links as $node) { //Get source of the image (src attribute) $img_src = $node->getAttribute('src'); //Get alt text of the image (alt attribute) $img_alt = $node->getAttribute('alt'); } } ?> Code (markup):
Totally and utterly incorrect. To the point of likely not even knowing enough PHP to try and answer this poor sod's question! That code is using PHP's built in DOMDocument OBJECT and its associated METHODS! Unfortunately for the OP, DOMDocument is inherently object based, since it turns HTML into the Document Object Model -- DOM. It is INHERENTLY object based just as HTML itself is. As such, there is no such thing as a procedural equivalent. ... and to be frank, even ASKING for a procedural equivalent likely means our little buddy hasn't learned enough HTML to be working with PHP yet. HTML is at its heart a plaintext representation of an object node tree. Each HTML element or section of context text is an object node, which has properties such as alt, src, id, class, type, etc, etc. A node in a tree can have parents, siblings, and children that are both objects in their own right, and properties of the relative element. This is why they are processed as objects, as they are objects. There is no such thing as a procedural equivalent and even attempting to do so would be an outright mentally enfeebled waste of time. Kind of like the mental midgetry of mysqli's procedural wrappers, just don't go there. You want to get into HTML processing this way, it's time to man up, strap up, put on the big boy pants, and learn objects. Laugh being this is entirely how it's handled in JavaScript, something else you should have a basic command of before diving into PHP. It's hypertext preprocessor -- it exists to be glue between data and markup... as such if you don't know the basics of HTML just what are you going to use it for?