Hi Fellas,
Thanks to effigy the Great who devised the belwo regex on my code i was able to match the data below. i am now trying to match one more pieces of data:
Current Data:
<PostCode>W1T 5AE</PostCode>
<PostCode>W1T 5A E </PostCode>
<PostCode>W1T 5AE-</PostCode>
Current regex:
preg_match_all('%
(?<=<PostCode>)
(
### 9 characters or more.
[^<]{9,}
|
### A hyphen.
[^<]*?-[^<]*?
|
### More than 1 space.
[^<]*?\s[^<]*?\s[^<]*?
)
(?=</PostCode>)%x',
the above works fine.
Now I also want to match this data:
<PostCode>1T 5AE</PostCode>
<PostCode>18T 5AE</PostCode>
i tried the following:
### A number
[^<]\d*?[^<]*?
but returns all postcodes??? it would be great if someone could care to help?
function parser()
{
$file_path= file_get_contents('xml.txt');
$file_count = count($file_path);
if($file_count==0)
{
print('file empty');
}
preg_match_all('%
(?<=<PostCode>)
(
### 9 characters or more.
[^<]{9,}
|
### A hyphen.
[^<]*?-[^<]*?
|
### A number.
[^<]\d*?[^<]*?
|
### More than 1 space.
[^<]*?\s[^<]*?\s[^<]*?
)
(?=</PostCode>)%x',
$file_path, $matches);
if ($matches)
{
$counter = count($matches[0]);
echo'<h1><font color=red>Invalid PostCodes found :'.$counter.'</font><br />';
while(list($key, $value)=each($matches[0]))
{
echo '=><input type=text size=13 value="'.$value.'"><br />';
}
}
}
parser();