/    Sign up×
Community /Pin to ProfileBookmark

How To Convert This OOP To Procedural Style Php ?

Folks,

I am a beginner and still on Procedural Style Php.
Do you mind converting this code to Procedural Style so I can learn from it to extract links off from a cURL fetched webpage ?

[code]
<?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(‘a’)) {
//Loop through all links
foreach($links as $node) {
//Get link location (href)
$link_href = $node->getAttribute(‘href’);
//Get link text
$link_text = $node->nodeValue;
}
}

?>

[/code]

Cheers!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmSep 10.2019 — Have you looked at the official PHP manual to see how functions are used in either OO or Procedural? Plenty of examples so that you can learn to do this yourself.

go to https://www.php.net/manual/en/funcref.php
Copy linkTweet thisAlerts:
@developer_webauthorSep 10.2019 — @ginerjm#1608579

Oh man, that link just lists a hundred more links!
Copy linkTweet thisAlerts:
@NogDogSep 10.2019 — That code is already procedural. Yes, it uses the built-in DOMDocument class, and therefore you have to use object/method notation via the -&gt; operator, but that's the only option if you want to use DOMDocument: there are no corresponding procedural-style PHP functions for it.

All you need is to research how to use the PHP cURL functions to grab the desired HTML from a URL and put the HTML into that $document variable, and then do whatever DOM manipulations you want. 🤷‍♂️
Copy linkTweet thisAlerts:
@ginerjmSep 10.2019 — ???

That is THE MANUAL. Learn to use it. It is not "links" but an index to all of the php functions covered in the book. IF you don't handle that well, perhaps you are heading into waters you don't want to be in.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...