tags:

views:

57

answers:

3
Hi i need to extract address from a string 
$string ="some text 9 th pizza tower 78 main Chennai 600001. and other information may be phone number etc";

From $string  i want to extract only  "9 th pizza tower 78 main Chennai 600001"

This Address format is not constan it may in two types 
one is string variable another one is like this 
$string1= "some text 9 th pizza tower main Chennai 600001. and other information may be phone number etc";

from here i need to extract  "9 th pizza tower main Chennai 600001"

Please help me thanks in advance
+1  A: 

I don't think this is possible...extracting text from a plain text file is like asking for a tree if you're in the woods, "Which one?".

If the file is always in the same format, like:

Company Name 73
1st Cross Street, Hotel Chennai
-600000
someadditionalstuff

Then you've got a change, or if it is always separated with a special character (, . ; etc.). If it is always the same format (the one you showed above), then something like this might work:

([a-zA-Z0-9 ]*),([a-zA-Z0-9 ]*) XXX ([a-zA-Z0-9 ]*) (-[0-9]{6})

Group 1: Company Name Group 2: Address Group 3: City Group 4: Zip-Code

Bobby

Bobby
Thanks adress mayy vary i want only 731st Cross Street, Hotel Chennai-600000 (without spec charac no prblem) for example in some times address like this 73 main road chennai 600000 .
Naresh
am having the address in varible $string="Company Name 731st Cross Street, Hotel Chennai-600000 and extra information";
Naresh
Is the 73 a fixed part?
Bobby
Microformats (http://microformats.org/) was an attempt to address issues like this, without the information being marked as an address, there's no obvious way for a machine to identify it as such.
MalphasWats
73 is not fixed
Naresh
@Naresh: You're most properly screwed, sorry...there's nothing there what would make it possible to separate the name from the address and so on...without a fixed format it's not possible.
Bobby
A: 

Sorry this is not possible. It may work for one website but not for others as there is no standard format in displaying a company address(or any address) on a web page.

ian
A: 

Not an easy question and there isn't a magic AI code that can figure it out. You must make some assumption , and look at a lot of data to find out if it's good ones.

for start - if you assume, every address ends with ZIP code, and you can search the string for 5 (or 6) digits and cut it after that.

TO find the start of the address is beyond my skills. maybe looking for the first number.

you need to check a lot of examples to figure out what would be the best patten that match most of them.

Dani
And - the other solution - make your user enter the address in a separate field and save yourself a lot of time.
Dani
Actually am getting this from web page as html and then i removed all tags (html ,script ,style) at last am having it in string
Naresh