tags:

views:

83

answers:

2

Hello, Does anyone have a fix for the following;

I'm taking the following string:

<span id="tmpl_main_lblWord" class="randomWord">kid</span>

and using the following preg_match / regex rule;

preg_match("'/(<span id=.* class=.*>)(.*)(<\/span>)/'si", $buffer, $match);

But its returning with an empty array any ideas?

+1  A: 

In general I would strongly advise against using regex to try and get values from HTML. I would use an HTML parser. See this question: http://stackoverflow.com/questions/292926/robust-mature-html-parser-for-php

If you insist though... you seem to have two sets of nested quotes. I would remove the inner single quotes. That should solve your problem.

Josiah
Thank you, I stripped nested works - worked great.
cocacola09
Glad to help :)
Josiah
+2  A: 

The following example uses DOMDocument:

$doc = new DOMDocument();
$doc->loadHtml('<span id="tmpl_main_lblWord" class="randomWord">kid</span>');
$el = $doc->getElementById('tmpl_main_lblWord');
echo 'Inner text is: ' . $el->textContent;
karim79
Thank you very useful.
cocacola09