Jump to content

doug007

Members
  • Posts

    62
  • Joined

  • Last visited

    Never

Everything posted by doug007

  1. doug007

    regex help

    what took you soo long works perfect
  2. try this. not sure if it will work though. preg_match("/^[-0-9A-Z_\[\]]*?\s+$/i", $attachname)
  3. doug007

    regex help

    Hi effigy i tried that, but it only matches the end of the string (see below)? its wiered as the metacharacter (^) should match the start? it matches this data: <PostCode>1T 5AE548</PostCode> <PostCode>18T 5AE14</PostCode> but should match this: <PostCode>1T 5AE</PostCode> <PostCode>18T 5AE</PostCode> cheers dug
  4. doug007

    regex help

    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();
  5. effigy you dog you done it million thanks.....i can sleep fine now.... cheers dug
  6. damn sorry ??? i meant to say if a additional space makes the postcode greater then 8 then print it otherwise if it has a space but total chars are less then 8 then its valid.
  7. no difference. it should output like so: <PostCode>W1T 5AEY</PostCode> -> invalid output more then 8 <PostCode>W1T 6AE</PostCode> -> valid dont output <PostCode>W1T 6A-E</PostCode> -> invalid output has hyphen
  8. this works, but it outputs all PostCode values. I only want to output PostCode values thus greater then 8, have hyphens, and a space. i looked at your regex, but dont really understand it to modify it myself. many thanks for you help
  9. data: <InYearMovements> <Employer> <Name>Badenoch & Clark</Name> <Address> <Line>Project House</Line> <Line>110-113 Tottenham Court Road</Line> <Line>London</Line> <PostCode>W1T 5AE</PostCode> </Address> </Employer> i wan to identify all invalid PostCodes that are more then 7 characters, or have spaces, have hyphens, but must start with a alpha and output them.
  10. nothing, i get an empty page.
  11. thanks for the feedback, I've been hammering my head figuring how to do this yet i still can not dont know if anyone can help fix my code? thanks
  12. Hi Guys I have a file containing entries like so <PostCode>WB5 7RT</PostCode>. so i want to identify all invalid postcodes ant output them. the regex that i need should grep the value between the '<PostCode>WB5 7RT</PostCode>' tags check that the first char is alpha, that it contains hyphens, and that it is greater then 8 characters. i've spent hours, yet no joy. function parse1() { $file_path= file('xml.txt'); $file_count = count($file_path); if($file_count==0) { print('file empty'); } $pattern='~\b<PostCode>[a-zA-Z]{1}[a-zA-Z0-9-]{8,}</PostCode>\b~'; $search = preg_quote($pattern); $result=preg_grep($pattern, $file_path); if ($result) { foreach($result as $value) { echo $value; } } } parse1();
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.