What regex code can i use to find an html tag, and then extract the string out of it?
<?php
$html = "<span class="equipped">360</span>"
$match = preg_match("???", $html, $matches);
?>
What regex code can i use to find an html tag, and then extract the string out of it?
<?php
$html = "<span class="equipped">360</span>"
$match = preg_match("???", $html, $matches);
?>
As npinti points out, you shouldn't use a regular expression to parse a non-regular language. Instead, you can use PHP's DOMDocument to find the text of any node you want. Here's an example for capturing the <span>
element's inner text and a demonstration to show how it works.
$html = "<span>Text</span>";
$doc = new DOMDocument();
$doc->loadHTML( $html);
$elements = $doc->getElementsByTagName("span");
foreach( $elements as $el)
{
echo $el->nodeValue . "\n";
}
Edit: My example shows using a semi-complete HTML document, but DOMDocument will also successfully parse an HTML string such as $html = '<span>Text</span>';
, see here.