Page 1 of 1

regex help please

Posted: Tue Oct 04, 2005 9:52 am
by SidewinderX
i posted something similar to this before and I got a response. I had hoped that I could learn from that example but I am still having troubell. Could someone please help me with this one too
Stats_lblPlayerName">WILD CHILD</span></span></td> <td sty.....
WILD CHILD is a name which can be any 16 alphanumeric characters (including any combination of spaces). I want to parse that string so i can extract and store the name as a variable. The beginning of the string is the same but the string continues for a while after <td sty.....

If you can help me, thanks

Posted: Tue Oct 04, 2005 12:03 pm
by anjanesh

Code: Select all

<pre>
<?php
$string = 'Stats_lblPlayerName">WILD CHILD</span></span></td> <td sty.....';

preg_match('#Stats_lblPlayerName">(.*?)</span>#is', $string, $matches);
$str = $matches[1];
echo $str;
?>

Posted: Tue Oct 04, 2005 9:27 pm
by SidewinderX
ok i incorperated that into a larger script and now i get this error
Notice: Undefined offset: 1 in d:\www3\JO\TOP50\stats.php on line 20
here is lines 17 - 22

Code: Select all

$html = htmlspecialchars($content);
$string = stristr($html, 'Stats_lblPlayer');
preg_match('#Stats_lblPlayerName">(.*?)</span>#is', $string, $matches);
$str = $matches[1];
echo $str;
any idea what that may mean?

Posted: Tue Oct 04, 2005 10:04 pm
by feyd
it didn't find any matches in the supplied string.

Posted: Tue Oct 04, 2005 10:08 pm
by sweatje
htmlspecialchars converted all > and < to > and <, and your regex is still looking for the symbols

Posted: Tue Oct 04, 2005 10:22 pm
by SidewinderX
oh, how do i design the regex properly?

Posted: Tue Oct 04, 2005 10:55 pm
by sweatje
delete lines 17 and 18 and do

Code: Select all

preg_match('#Stats_lblPlayerName">(.*?)</span>#is', $content, $matches);
instead for 19