Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Example:

@article{boonzaier2009development,
author = "Boonzaier, A. and Schubach, K. and Troup, K. and Pollard, A. and Aranda, S. and Schofield, P.",
title = "Development of a psychoeducational intervention ",
journal = "Journal of Psychosocial Oncology",
volume = "27",
number = "1",
pages = "136-153",
year = 2009
}

@book{bottoff2008women,
author = "Bottoff, J. L. and Oliffe, J. L. and Halpin, M. and Phillips, M. and McLean, G. and Mroz, L.",
title = "Women and prostate cancer support groups: {The} gender connect? {Social} {Science} & {Medicine}",
publisher = "66",
pages = "1217-1227",
year = 2008
}

@article{bottorff2012gender,
author = "Bottorff, J. L. and Oliffe, J. L. and Kelly, M.",
title = "The gender (s) in the room",
journal = "Qualitative Health Research",
volume = "22",
number = "4",
pages = "435-440",
year = 2012
}
I want to capture the string between double quotes of @article part only. Am getting the count of @article and range of @article fields to get the values of @article elements. Using for loop am getting values of @article (for loop values: range of @article to next @article and so on) The problem is, for example first string @article is in 10th line and second one is in 18 th line, am doing for loop between this range and getting the value but, inbetween @book also is there so how to eliminate that @book range of lines in for loop. Because it captures @book elements also as it is inside in the range of @article.

php code:
PHP
<?php
$file=file("master.bib");
$typeart=array();
$cont=array();

//count of article
$key = '@article';
foreach ($file as $l => $line) {
    if (strpos($line,$key) !== false) {
       $l++;
       $typeart[]= $l;

          }
}//end-count of article

$counttypeart=count($typeart);

for($j=0;$j<$counttypeart;$j++){

    for($i=$typeart[$j];$i<$typeart[$j+1];$i++){
if(strpos($file[$i],'author')){
preg_match('/\"(.*?)\"/',$file[$i],$cont);
$author= $cont[1];
echo $author;
echo ;
}
if(strpos($file[$i],'title')){
preg_match('/\"(.*?)\"/',$file[$i],$cont);
$title= $cont[1];
echo $title;
echo ;
}
if(strpos($file[$i],'journal')){
preg_match('/\"(.*?)\"/',$file[$i],$cont);
$journal= $cont[1];
echo $journal;
echo ;
}

if(strpos($file[$i],'volume')){
preg_match('/\"(.*?)\"/',$file[$i],$cont);
$volume= $cont[1];
echo $volume;
echo ;
}

if(strpos($file[$i],'number')){
preg_match('/\"(.*?)\"/',$file[$i],$cont);
$number= $cont[1];
echo $number;
echo ;
}

if(strpos($file[$i],'pages')){
preg_match('/\"(.*?)\"/',$file[$i],$cont);
$pages= $cont[1];
echo $pages;
echo ;
echo ;
}
}
}

?>


Expected output (From above mentioned example):

Boonzaier, A. and Schubach, K. and Troup, K. and Pollard, A. and Aranda, S. and Schofield P.
Development of a psychoeducational intervention for men with prostate cancer
Journal of Psychosocial Oncology
27
1
136-153


Bottorff, J. L. and Oliffe, J. L. and Kelly, M.
The gender (s) in the room
Qualitative Health Research
22
4
435-440
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900