Page 1 of 1

preg_match output

Posted: Thu Apr 17, 2008 5:03 am
by rsmarsha
I have the following code :

Code: Select all

 
preg_match('/<nobr[>][a-zA-Z]+<\/nobr><\/td>[\s]*<td class="fieldValue">[a-zA-z]+<\/td>/', '<nobr>Server</nobr></td> <td class="fieldValue">Name</td>other text not needed', $matches);
print_r($matches);
 
Which prints out "Array ( [0] => Server Name ) "

Is it possible to have it only pick out the Name part of the match? Or would i just have to use further functions to get that. The actual string to match will be a variable containing a html page and the "Name" section will vary.

Re: preg_match output

Posted: Sun Apr 20, 2008 2:35 am
by prometheuzz
Try this:

Code: Select all

 
preg_match(
    '/<nobr[>][a-zA-Z]+<\/nobr><\/td>[\s]*<td class="fieldValue">([a-zA-Z]+)<\/td>/', 
    '<nobr>SERVER</nobr></td> <td class="fieldValue">NAME</td>other text not needed', 
    $matches);
print_r($matches);
print("\nName only: " . $matches[1] . "\n");