Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
SidewinderX
Forum Contributor
Posts: 407 Joined: Fri Jul 16, 2004 9:04 pm
Location: NY
Post
by SidewinderX » Tue Oct 04, 2005 9:52 am
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
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Tue Oct 04, 2005 12:03 pm
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 » Tue Oct 04, 2005 9:27 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Oct 04, 2005 10:04 pm
it didn't find any matches in the supplied string.
sweatje
Forum Contributor
Posts: 277 Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA
Post
by sweatje » Tue Oct 04, 2005 10:08 pm
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 » Tue Oct 04, 2005 10:22 pm
oh, how do i design the regex properly?
sweatje
Forum Contributor
Posts: 277 Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA
Post
by sweatje » Tue Oct 04, 2005 10:55 pm
delete lines 17 and 18 and do
Code: Select all
preg_match('#Stats_lblPlayerName">(.*?)</span>#is', $content, $matches);instead for 19