I
I
ImSoSorry2020-02-20 14:29:46
JavaScript
ImSoSorry, 2020-02-20 14:29:46

How to parse link names in php?

Good day, I ran into a problem, the customer has an old site, but there is no access to the database.

You need to parse category link names, the link structure is simple:

<a href="/clothing/jacket/">Jacket</a>
<a href="/clothing/Socks/">Socks</a>

etc.
(there are quite a lot of such categories, not by hand)

Question:
How can I get only the names of all links on the page using php? I searched the internet and didn't find anything similar. Newbie.

UPD: In the future, the goal is to restore the database from the received data

Answer the question

In order to leave comments, you need to log in

7 answer(s)
D
Dmitry Luzanov, 2019-06-22
@nurpais95

- Global variables
- Hard-coded classes
If you're going to use it as a plugin, then no. If it works on your project and suits you - ok.

J
Jacob Holus, 2019-06-22
@artemkotok

everything is right

S
SagePtr, 2019-06-23
@SagePtr

better wrap it in at least a closure so that your code doesn't pollute the global window object.

A
AUser0, 2020-02-20
@ImSoSorry

$html = file_get_contents("http://site.org/path/index.php");
if (preg_match_all("#<a href=\"[^\"]+\">(.+?)</a>#", $html, $regs, PREG_PATTERN_ORDER))
{
    foreach($regs[1] as $v) echo("{$v}\n");
}

But if you don't even know this, you won't get far from this code... Hire a specialist.

S
Stalker_RED, 2020-02-20
@Stalker_RED

This is some kind of sur. Access to the database was stolen by aliens?
Well, here is a regular expression, for example https://regex101.com/r/TuQdqY/1/
Or read about some normal parser, such as dom-crawler, DiDom or zend_dom_query

T
ThunderCat, 2020-02-20
@ThunderCat

but no db access.
What about the code? Or the customer does not have a website at all, but whose website xs?

V
Valentyn, 2020-02-20
@rotarepmipoleved

$pattern - https://regex101.com/r/Qsocuh/1
preg_match_all($pattern, $html, $match)
Next, work with $match

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question