Using a regex, how can I delete/replace everything and keep only the score inside the tag?
The data-v
is variable.
<a href="/football/italy/1-division-phase-a/fixtures/7-days/#" data-y="f1" data-v="this-is-variable">2 - 0</a>
Using a regex, how can I delete/replace everything and keep only the score inside the tag?
The data-v
is variable.
<a href="/football/italy/1-division-phase-a/fixtures/7-days/#" data-y="f1" data-v="this-is-variable">2 - 0</a>
You can use regex in preg_match()
to select target part of string.
preg_match("/>([^<]+)</", $str, $matches);
echo $matches[1];
See result in demo
Also because your string is html, you can parse it using DOMDocument
class and get text of element.
$dom = DOMDocument::loadHTML($str);
$text = $dom->getElementsByTagName("a")->item(0)->nodeValue;
See result in demo