如何从php中的大文本中获取字符串数组

时间:2016-03-21 05:32:16

标签: php arrays

我想从这个字符串中获取一个字符串数组。 这是我的原始字符串$str

$str='
Abhiramapuram
Abhiramapuram
Agartala
Agartala
Agra
Agra
Ahmedabad
Ahmedabad
Ahmednagar
Ahmednagar
Aizawl
Aizawl
Ajmer
Ajmer
Alibaug
Alibaug
Aligarh
Aligarh
Allahabad
Allahabad
Alleppey
Alleppey
Almora
Almora
Alsisar
Alsisar
Alwar
Alwar
Ambala
Ambala
Amla
Amla
Amritsar
Amritsar
Anand
Anand
Anantapur
Anantapur
Andaman
Andaman
Ankleshwar
Ankleshwar
Ankola
Ankola
Araku
Araku
Aronda
Aronda
Ashtamudi
Ashtamudi
Auli
Auli
Aurangabad
Aurangabad
B R Hills
B R Hills
Badami
Badami
Baddi
Baddi
Badrinath
Badrinath
Balaghat
Balaghat
Balasinor
Balasinor
Balrampur
Balrampur
Bambora
Bambora
Bandhavgarh
Bandhavgarh
Bandipur
Bandipur
Bangalore
Bangalore
Barbil
Barbil
Bareilly
Bareilly
Bathinda
Bathinda
Behror
Behror
Belgaum
Belgaum
Bellary
Bellary
Belur Halebedu
Belur Halebedu
Berhampur
Berhampur
Betalghat
Betalghat
Bhandardara
Bhandardara
Bharatpur
Bharatpur
Bharuch
Bharuch
Bhavangadh
Bhavangadh
Bhavnagar
Bhavnagar
Bhilai
Bhilai
Bhilwara
Bhilwara
Bhimtal
Bhimtal
Bhiwadi
Bhiwadi
Bhopal
Bhopal
Bhubaneshwar
Bhubaneshwar
Bhuj
Bhuj
Bijapur
Bijapur
Bikaner
Bikaner
Bilaspur
Bilaspur
Binsar
Binsar
Biratnagar
Biratnagar
Birganj
Birganj
Bodhgaya
Bodhgaya
Bomdila
Bomdila
Bordi
Bordi
Bundelkhand
Bundelkhand
Bundi
Bundi
Calicut
Calicut
Canannore
Canannore
Chail
Chail
Chalsa
Chalsa
Chamarajanagar
Chamarajanagar
Chamba-Uttaranchal
Chamba-Uttaranchal
Chamba-Himachal
Chamba-Himachal
Chamunda
Chamunda
Chandigarh
Chandigarh
Chennai
Chennai
Chettinad
Chettinad
Chhota Udepur
Chhota Udepur
Chidambaram
Chidambaram
Chikmagalur
Chikmagalur
Chiplun
Chiplun
Chitrakoot
Chitrakoot
Chittoor
Chittoor
Chittorgarh
Chittorgarh
Chitwan
Chitwan
Cochin
Cochin
Coimbatore
Coimbatore
Coonoor
Coonoor
Coorg
Coorg
Corbett
Corbett
Courtallam
Courtallam
Cuddalore
Cuddalore
Cuttack
Cuttack
Dabhosa
Dabhosa
Dahej
Dahej
Dalhousie
Dalhousie
Daman
Daman
Dandeli
Dandeli
Dapoli
Dapoli
Darjeeling
Darjeeling
Dasada
Dasada
Dausa
Dausa
Dehradun
Dehradun
Dechu
Dechu
Dhanaulti
Dhanaulti
Dhankuta-Nepal
Dhankuta-Nepal
Dharamshala
Dharamshala
Dharan-Nepal
Dharan-Nepal
Dharmapuri
Dharmapuri
Dharmastala
Dharmastala
Dholpur
Dholpur
Dhulikel-Nepal
Dhulikel-Nepal
Dibrugarh
Dibrugarh
Digha
Digha
Dindigul
Dindigul
Diu
Diu
Dive Agar
Dive Agar
Dooars
Dooars
Durgapur
Durgapur
Durshet
Durshet
Dwarka
Dwarka
Erode
Erode
Faridabad
Faridabad
Firozabad
Firozabad
Galle
Galle
Gandhidham
Gandhidham
Gandhinagar
Gandhinagar
Gangavathi
Gangavathi
Gangotri
Gangotri
Gangtok
Gangtok
Ganpatipule
Ganpatipule
Garhmukteshwar
Garhmukteshwar
Garhwal
Garhwal
Gaya
Gaya
Ghaziabad
Ghaziabad
Gir
Gir
Goa
Goa
Gokarna
Gokarna
Gondal
Gondal
Gorakhpur
Gorakhpur
Greater Noida
Greater Noida
Gulmarg
Gulmarg
Gurgaon
Gurgaon
Guruvayoor
Guruvayoor
Guwahati
Guwahati
Gwalior
Gwalior
Gyalshing
Gyalshing
Haldwani
Haldwani
Halebidu
Halebidu
Hampi
Hampi
Hansi
Hansi
Haridwar
Haridwar
Hassan
Hassan
Havelock
Havelock
Hogenakkal
Hogenakkal
Hospet
Hospet
Hosur
Hosur
Hubli
Hubli
Hyderabad
Hyderabad
Idukki
Idukki
Igatpuri
Igatpuri
Itanagar
Itanagar
Ilam
Ilam
Imphal
Imphal
Indore
Indore
Jabalpur
Jabalpur
Jaipur
Jaipur
Jaisalmer
Jaisalmer
Jaisamand
Jaisamand
Jalandhar
Jalandhar
Jalgaon
Jalgaon
Jambughoda
Jambughoda
Jammu
Jammu
Jamnagar
Jamnagar
Jamshedpur
Jamshedpur
Jawhar
Jawhar
Jhansi
Jhansi
Jodhpur
Jodhpur
Jojawar
Jojawar
Jorhat
Jorhat
Junagadh
Junagadh
Kabini
Kabini
Kakinada
Kakinada
Kalimpong
Kalimpong
Kanatal
Kanatal
Kanchipuram
Kanchipuram
Kangra
Kangra
Kanha
Kanha
Kannur
Kannur
Kanpur
Kanpur
Kanyakumari
Kanyakumari
Karaikudi
Karaikudi
Karauli
Karauli
Kargil
Kargil
Karjat
Karjat
Karnal
Karnal
Karur
Karur
Karwar
Karwar
Kasargod
Kasargod
Kasauli
Kasauli
Kashid
Kashid
Kashipur
Kashipur
Kashmir
Kashmir
Kataragama
Kataragama
Kathmandu-Nepal
Kathmandu-Nepal
Katra
Katra
Kausani
Kausani
Kaza
Kaza
Kaziranga
Kaziranga
Kedarnath
Kedarnath
Khajjiar
Khajjiar
Khajuraho
Khajuraho
Khandala
Khandala
Khejarla
Khejarla
Khimsar
Khimsar
Khurpatal
Khurpatal
Kochin
Kochin
Kodaikanal
Kodaikanal
Kolhapur
Kolhapur
Kolkata
Kolkata
Kollam
Kollam
Konkan
Konkan
Kota
Kota
Kotagiri
Kotagiri
Kottayam
Kottayam
Kovalam
Kovalam
Krishnagiri
Krishnagiri
Kufri
Kufri
Kullu
Kullu
Kumarakom
Kumarakom
Kumbakonam
Kumbakonam
Kumbalgarh
Kumbalgarh
Kundapur
Kundapur
Kurnool
Kurnool
Kurseong
Kurseong
Kushinagar
Kushinagar
Kutch
Kutch
Kutrallam
Kutrallam
Lachung
Lachung
Lakshadweep
Lakshadweep
Lansdowne
Lansdowne
Lavasa
Lavasa
Leh
Leh
Lonavala
Lonavala
Lothal
Lothal
Lucknow
Lucknow
Ludhiana
Ludhiana
Lumbini
Lumbini
Madurai
Madurai
Mahabaleshwar
Mahabaleshwar
Mahabalipuram
Mahabalipuram
Malappuram
Malappuram
Malpe
Malpe
Malshej Ghat
Malshej Ghat
Malvan
Malvan
Mamallapuram
Mamallapuram
Manali
Manali
Mandavi
Mandavi
Mandawa
Mandawa
Mandarmani
Mandarmani
Mandi
Mandi
Manesar
Manesar
Mangalore
Mangalore
Mangan
Mangan
Manipal
Manipal
Manmad
Manmad
Marari
Marari
Marchula
Marchula
Masinagudi
Masinagudi
Matheran
Matheran
Mathura
Mathura
Mayiladuthurai
Mayiladuthurai
Mcleodganj
Mcleodganj
Meerut
Meerut
Mettupalayam
Mettupalayam
Mirik
Mirik
Mohali
Mohali
Moradabad
Moradabad
Morbi
Morbi
Mount Abu
Mount Abu
Mukteshwar
Mukteshwar
Mumbai
Mumbai
Mundra
Mundra
Munnar
Munnar
Murud Janjira
Murud Janjira
Mussoorie
Mussoorie
Mysore
Mysore
Nadukani
Nadukani
Nagapattinam
Nagapattinam
Nagarhole
Nagarhole
Nagarkot
Nagarkot
Nagaur
Nagaur
Nagercoil
Nagercoil
Nagothane
Nagothane
Nagpur
Nagpur
Nahan
Nahan
Nainital
Nainital
Naldehra
Naldehra
Namakkal
Namakkal
Nanded
Nanded
Napne
Napne
Nashik
Nashik
Nathdwara
Nathdwara
Naukuchiatal
Naukuchiatal
Navi Mumbai
Navi Mumbai
Nawalgarh
Nawalgarh
Neemrana
Neemrana
Nellore
Nellore
Nepalgunj-Nepal
Nepalgunj-Nepal
Neral
Neral
New Delhi
New Delhi
Nilgiri
Nilgiri
Nizamabad
Nizamabad
Noida
Noida
Ooty
Ooty
Orchha
Orchha
Osian
Osian
Pachmarhi
Pachmarhi
Pahalgam
Pahalgam
Palakkad
Palakkad
Palampur
Palampur
Palani
Palani
Palanpur
Palanpur
Pali
Pali
Palitana
Palitana
Panchgani
Panchgani
Panchkula
Panchkula
Panhala
Panhala
Panna
Panna
Pantnagar
Pantnagar
Panvel
Panvel
Paota
Paota
Paradip
Paradip
Parwanoo
Parwanoo
Pathankot
Pathankot
Patiala
Patiala
Patna
Patna
Patnitop
Patnitop
Pelling
Pelling
Pench
Pench
Phagwara
Phagwara
Phalodi
Phalodi
Pinjore
Pinjore
Pithoragarh
Pithoragarh
Pokhara
Pokhara
Pollachi
Pollachi
Pondicherry
Pondicherry
Poovar
Poovar
Porbandar
Porbandar
Port Blair
Port Blair
Poshina
Poshina
Pragpur
Pragpur
Pudukkottai
Pudukkottai
Pune
Pune
Puri
Puri
Pushkar
Pushkar
Puttaparthi
Puttaparthi
Raebareli
Raebareli
Raichak
Raichak
Raigarh
Raigarh
Raipur
Raipur
Rajahmundry
Rajahmundry
Rajasthan
Rajasthan
Rajgir
Rajgir
Rajkot
Rajkot
Rajpipla
Rajpipla
Rajsamand
Rajsamand
Rajula
Rajula
Ramnagar
Ramnagar
Rameshwaram
Rameshwaram
Ramgarh
Ramgarh
Ranakpur
Ranakpur
Ranchi
Ranchi
Ranikhet
Ranikhet
Ranny
Ranny
Ranthambore
Ranthambore
Ratnagiri
Ratnagiri
Ravangla
Ravangla
Rewari
Rewari
Rishikesh
Rishikesh
Rishyap
Rishyap
Rohetgarh
Rohetgarh
Roorkee
Roorkee
Ropar
Ropar
Rourkela
Rourkela
Rudrapur
Rudrapur
Sajan
Sajan
Sakleshpur
Sakleshpur
Salem
Salem
Sanawar
Sanawar
Saputara
Saputara
Sariska
Sariska
Sasan Gir
Sasan Gir
Sattal
Sattal
Sawai Madhopur
Sawai Madhopur
Sawantwadi
Sawantwadi
Secunderabad
Secunderabad
Seoni
Seoni
Shahapur
Shahapur
Shravana Belagola
Shravana Belagola
Shekhawati
Shekhawati
Shillong
Shillong
Shimla
Shimla
Similipal
Similipal
Shimoga
Shimoga
Shirdi
Shirdi
Shivanasamudra
Shivanasamudra
Siana
Siana
Siliguri
Siliguri
Silvassa
Silvassa
Sivaganga
Sivaganga
Sivakasi
Sivakasi
Solan
Solan
Somnath
Somnath
Sunauli
Sunauli
Srinagar
Srinagar
Sriperumbudur
Sriperumbudur
Srirangapatna
Srirangapatna
Sundarban
Sundarban
Surat
Surat
Tanjore
Tanjore
Tapola
Tapola
Tarapith
Tarapith
Tawang
Tawang
Tezpur
Tezpur
Talakad
Talakad
Thane
Thane
Thekkady
Thekkady
Theni
Theni
Thiruvananthapuram
Thiruvananthapuram
Thiruvannamalai
Thiruvannamalai
Thrissur
Thrissur
Tiruchendur
Tiruchendur
Tirunelveli
Tirunelveli
Tirupati
Tirupati
Tirupur
Tirupur
Tiruchirapalli
Tiruchirapalli
Trichy
Trichy
Tuticorin
Tuticorin
Udaipur
Udaipur
Udhampur
Udhampur
Udupi
Udupi
Ujjain
Ujjain
Umaria
Umaria
Utelia
Utelia
Uttarkashi
Uttarkashi
Vadasinor
Vadasinor
Vadodara
Vadodara
Vagamon
Vagamon
Vaishno Devi
Vaishno Devi
Vapi
Vapi
Varanasi
Varanasi
Varkala
Varkala
Vailankanni
Vailankanni
Vellore
Vellore
Veraval
Veraval
Vijayawada
Vijayawada
Vikramgadh
Vikramgadh
Visakhapatnam
Visakhapatnam
Wankaner
Wankaner
Warrangal
Warrangal
Wayanad
Wayanad
West Kameng
West Kameng
Yamunotri
Yamunotri
Yelagiri
Yelagiri
Yercaud
Yercaud
Yuksom
Yuksom'

我尝试过explode

$newarr=explode(' ',$str);
foreach($newarr $val){
  echo $val;
}

但这并没有奏效。

1 个答案:

答案 0 :(得分:2)

尝试通过"\n"新行字符进行爆炸。

$array = explode("\n", $str);
print_r($array);