Problems using RegExps
Posted: Thu Jul 29, 2004 4:27 am
Hello,
I would like to parse a string and have problems using RegExps. The ouput of the following code snippet is bellow.
I just want everything behind each descr in an array like this:
==> What is wrong in my script, since I'm getting empty strings? O.k., I guess my regexp is wrong... :(
Input:
---------
Output:
---------
feyd | added
I would like to parse a string and have problems using RegExps. The ouput of the following code snippet is bellow.
I just want everything behind each descr in an array like this:
Code: Select all
array(10) {
ї0]=>
string(0) "SPIEGEL ONLINE GmbH"
ї1]=>
string(0) "Brandstwiete 19"
ї2]=>
string(0) "20457 Hamburg"
ї3]=>
string(0) "Germany"
}Code: Select all
[...]
$output = extractBlocks($rawoutput,'domain:','source:');
echo $output;
//Parse string with RegExps
$arrData = getDataUsingRegexp('|:(.*)\s|U',$output);
goDumpArray($arrData);
[...]
function getDataUsingRegexp($strRegexp,$string)
{
preg_match_all($strRegexp, $string, $matches);
$arrListe = array();
for ($i=0; $i< count($matches[0]); $i++)
{
$strData = trim($matches[1][$i]);
$arrListe[] = $strData;
}
return $arrListe;
}Input:
---------
Code: Select all
domain: spiegel.de
descr: SPIEGEL ONLINE GmbH
descr: Brandstwiete 19
descr: 20457 Hamburg
descr: Germany
nserver: igate.spiegel.de 194.64.251.5
nserver: dns-s.is-europe.net
nserver: sec-s.is-europe.net
status: connect
changed: 2003-08-16T05:05:38+0200
source: DENIC---------
Code: Select all
spiegel.de
descr: SPIEGEL ONLINE GmbH
descr: Brandstwiete 19
descr: 20457 Hamburg
descr: Germany
nserver: igate.spiegel.de 194.64.251.5
nserver: dns-s.is-europe.net
nserver: sec-s.is-europe.net
status: connect
changed: 2003-08-16T05:05:38+0200
array(10) {
ї0]=>
string(0) ""
ї1]=>
string(0) ""
ї2]=>
string(0) ""
ї3]=>
string(0) ""
ї4]=>
string(0) ""
ї5]=>
string(0) ""
ї6]=>
string(0) ""
ї7]=>
string(0) ""
ї8]=>
string(0) ""
ї9]=>
string(10) "05:38+0200"
}feyd | added
Code: Select all
tags around I/O[/color]
[color=red][b]Bech100[/b] | Disabled smilies cos they were screwing up the php[/color]