regex help please

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

regex help please

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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;
?>
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it didn't find any matches in the supplied string.
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

htmlspecialchars converted all > and < to > and <, and your regex is still looking for the symbols
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

oh, how do i design the regex properly?
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

delete lines 17 and 18 and do

Code: Select all

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