Answer the question
In order to leave comments, you need to log in
How to get a link regularly?
Hello, you need to select all url links from:
a href=" https://site.com/aaa-bbb-ccc-ddd-eee-fff-eee "
a href=" https://site.com/aaaaa- bbbb-ccccccc-ddddd-eeeee "
but under one condition: if the link contains more than 3 characters" - "
i.e. such a link a href=" https://site.com/aaa-bbb-ccc will not work
Tell me please how can this be done
Answer the question
In order to leave comments, you need to log in
href\=\"(.*)\"
$output = [];
$html = '
<a href="https://site.com/aaa-bbb-ccc-ddd-eee-fff-eee">
<a href="https://site.com/aaa-bbb-ccc">
<a href="https://site.com/aaaaa-bbbb-ccccccc-ddddd-eeeee">';
preg_match_all('/href\=\"(.*)\"/', $html, $matches);
foreach($matches[1] as $link) {
$dashes = explode('-', $link);
if (count($dashes) > 3) $output[] = $link;
}
var_dump($output);
Hello!
There is a site for generating regular expressions - txt2re.com will
suddenly help you)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question