Как уже упоминалось в комментариях, обычно не стоит пытаться извлекать вещи из HTML с помощью регулярных выражений. Если вы когда-нибудь захотите перейти на более пуленепробиваемый метод, приведу краткий пример того, как вы можете легко извлечь информацию, используя DOMDocument API.
<?php
function get_vboxview($html) {
$output = array();
// Create a new DOM object
$doc = new DOMDocument;
// load a string in as html
$doc->loadHTML($html);
// create a new Xpath object to query the document with
$xpath = new DOMXPath($doc);
// an xpath query that looks for a vboxview node anywhere in the DOM
// with an attribute named leftinset set to 10, an attribute named rightinset
// set to 0 and an attribute named stretchiness set to 1
$query = '//vboxview[@leftinset=10 and @rightinset=0 and @stretchiness=1]';
// query the document
$matches = $xpath->query($query);
// loop through each matching node
// and the textContent to the output
foreach ($matches as $m) {
$output[] = $m->textContent;
}
return $output;
}
?>
Еще лучше, если в вашем входе гарантированно будет только один vboxview
(также при условии, что у вас есть контроль над HTML), вы можете добавить атрибут id
к vboxview
и сократить код до более короткого и более обобщенная функция.
<?php
function get_node_text($html, $id) {
// Create a new DOM object
$doc = new DOMDocument;
// load a string in as html
$doc->loadHTML($html);
// return the textContent of the node with the id $id
return $doc->getElementById($id)->textContent;
}
?>