Tuesday, October 8, 2013

PHP, split summary text data from pubmed using preg_split and preg_match


I have summary text data from pubmed and I want to separate them into author, title, author, date and pubid etc. The PHP code:
<?php
//Journal list number and authorlist
$pmregex = '/^(\d+): (.+?)\.'

//article title
         . ' (.+?)\.'

// (.+?)  Journal name such as Oral Dis
// \. (\d\d\d\d)(.*?);  . 2013 Jul
// ;(.+?)     :19 (5)
//:(\w+)-?(\w*?) page number such as  440-451
// add \n? after considering 0+ line break
         . '(.+?)[\. \n?](\d\d\d\d)(.*?);(.+?):(\w+)-?(\w*?)[\.\;](.*)'
//PMID number
       . '[PMID: \n?](\d+)'
         . '/s';
$data="1: Saini R, Poh C. Photodynamic therapy: a review and its prospective role in the
management of oral potentially malignant disorders. Oral Dis. 2013
Jul;19(5):440-451. doi: 10.1111/odi.12003. PubMed PMID: 24079944.



2: Powell JJ, Apiratpracha W, Partovi N, Erb SR, Scudamore CH, Steinbrecher UP,
Buczkowski AK, Chung SW, Yoshida EM. Subcutaneous administration of hepatitis B
immune globulin in combination with lamivudine following orthotopic liver
transplantation: effective prophylaxis against recurrence. Clin Transplant. 2006
Jul-Aug;20(4):524-5. PubMed PMID: 16842532.
";
//[\r\n]: newline, \d+:  separator is digital numbers followed by : ,
//?=Separator is included in the output array
$choppeddata = preg_split('/([\r\n])(?=\d+: )/',$data);

foreach($choppeddata as $subdata)
{
print_r($subdata);
echo '<br /><br />';
preg_match($pmregex, trim($subdata), $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
}
?>

Running result:
1: Saini R, Poh C. Photodynamic therapy: a review and its prospective role in the management of oral potentially malignant disorders. Oral Dis. 2013 Jul;19(5):440-451. doi: 10.1111/odi.12003. PubMed PMID: 24079944.
Array
(
    [0] => 1: Saini R, Poh C. Photodynamic therapy: a review and its prospective role in the
management of oral potentially malignant disorders. Oral Dis. 2013
Jul;19(5):440-451. doi: 10.1111/odi.12003. PubMed PMID: 24079944
    [1] => 1
    [2] => Saini R, Poh C
    [3] => Photodynamic therapy: a review and its prospective role in the
management of oral potentially malignant disorders
    [4] =>  Oral Dis
    [5] => 2013
    [6] => 
Jul
    [7] => 19(5)
    [8] => 440
    [9] => 451
    [10] =>  doi: 10.1111/odi.12003. PubMed 
    [11] => 24079944
)
2: Powell JJ, Apiratpracha W, Partovi N, Erb SR, Scudamore CH, Steinbrecher UP, Buczkowski AK, Chung SW, Yoshida EM. Subcutaneous administration of hepatitis B immune globulin in combination with lamivudine following orthotopic liver transplantation: effective prophylaxis against recurrence. Clin Transplant. 2006 Jul-Aug;20(4):524-5. PubMed PMID: 16842532.
Array
(
    [0] => 2: Powell JJ, Apiratpracha W, Partovi N, Erb SR, Scudamore CH, Steinbrecher UP,
Buczkowski AK, Chung SW, Yoshida EM. Subcutaneous administration of hepatitis B
immune globulin in combination with lamivudine following orthotopic liver
transplantation: effective prophylaxis against recurrence. Clin Transplant. 2006 
Jul-Aug;20(4):524-5. PubMed PMID: 16842532
    [1] => 2
    [2] => Powell JJ, Apiratpracha W, Partovi N, Erb SR, Scudamore CH, Steinbrecher UP,
Buczkowski AK, Chung SW, Yoshida EM
    [3] => Subcutaneous administration of hepatitis B
immune globulin in combination with lamivudine following orthotopic liver
transplantation: effective prophylaxis against recurrence
    [4] =>  Clin Transplant
    [5] => 2006
    [6] =>  
Jul-Aug
    [7] => 20(4)
    [8] => 524
    [9] => 5
    [10] =>  PubMed 
    [11] => 16842532
) 
 

 
 
 

1 comment:

  1. I have long felt a special connection with herbal medicine. First, it's natural, Charlie attended the same small college in Southern California - Claremont Men's College - although he dropped out of school to enroll in the Julliard School of Performing Arts in New York. York. Had he been to Claremont, he would have been senior the year I started there; I often thought that was the reason he was gone when he discovered that I had herpes. So, my life was lonely, all day, I could not stand the pain of the outbreak, and then Tasha introduced me to Dr. Itua who uses her herbal medicines to cure her two weeks of consumption. I place an order for him and he hands it to my post office, then I pick it up and use it for two weeks. All my wound is completely healed no more epidemic. I tell you honestly that this man is a great man, I trust him Herbal medicine so much that I share this to show my gratitude and also to let sick people know that there is hope with Dr. Itua. Herbal Center.Dr Itua Contact Email.drituaherbalcenter@gmail.com/Whatsapp ... 2348149277967
    He cures.
    Herpes,
    Prostate
    Breast Cancer
    Brain Cancer
    CEREBRAL VASCULAR ACCIDENT.
    ,Endomertil Cancer, cerebrovascular diseases
    Hepatitis,Glaucoma., Cataracts,Macular degeneration,Cardiovascular disease,Lung disease.Enlarged prostate,Osteoporosis.Alzheimer's disease,
    Dementia.Tach Disease,Shingles,
    Lung Cancer, Leukemia Lymphoma Cancer,
    Lung Mesothelioma Asbestos,
    Ovarian Cervical Uterine Cancer,
    Skin Cancer, Brain Tumor,
    H.P.V TYPE 1 TYPE 2 TYPE 3 AND TYPE 4. TYPE 5.
    HIV,Arthritis,Amyotrophic Lateral Scoliosis,Fibromyalgia,Fluoroquinolone Toxicity
    Cervical Cancer
    Colo-rectal Cancer
    Blood Cancer
    SYPHILIS.
    Diabetes
    Liver / Inflammatory kidney
    Epilepsy

    ReplyDelete