如何捕获PHP中双引号之间的字符串? [英] How to capture the string between double quotes in php?

查看:538
本文介绍了如何捕获PHP中双引号之间的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:



@article {ames2011pilot,

author =Ames,SC和Tan,WW和Ames,GE和Stone ,RL和Rizzo Jr以及TD和Crook,JE和Williams,CR和Werch,CE和Clark,MM和Rummans,TA,

title =试点调查,

journal =Psycho-oncology,

volume =20,

number =4,

pages = 435-440,

年= 2011

}



我只需要获得标题值之间的答案应该是一个试点调查。

我尝试了下面的PHP代码,但我得到双引号之间的所有值不仅是标题值。



 <?php  
$ file = file( master.bib);
$ m = array();
$ c = count($ file);
for($ i = 0; $ i< $ c; $ i ++){
// article-start
if((strpos($ file [$ i], @ article))== 0){
// title-start
if((strpos($ file [$ i], title))< ; = 3){
preg_match(' / \(。*?)\/' ,$文件[$ i]于,$米);
echo $ m [1];
echo < br>;

// end-title
}
}
// 文章结尾
}





我不知道这里有什么不对。这是在我需要的时候在双引号之间获取值的有效方法。

解决方案

file = file( master.bib);


m = array();


C =计数(

Example:

@article{ames2011pilot,
author = "Ames, S. C. and Tan, W. W. and Ames, G. E. and Stone, R. L. and Rizzo Jr and T. D. and Crook, J. E. and Williams, C. R. and Werch, C. E. and Clark, M. M. and Rummans, T. A.",
title = "A pilot investigation ",
journal = "Psycho‐oncology",
volume = "20",
number = "4",
pages = "435-440",
year = 2011
}

I need to get only title values which is between "".The ans should be, A pilot investigation.
I tried the following php code,but am getting all the values between double quotes not only title value.

<?php
$file=file("master.bib");
$m=array();
$c=count($file);
for($i=0;$i<$c;$i++){
//article-start
if((strpos($file[$i],"@article"))==0){
//title-start
if((strpos($file[$i],"title"))<=3){
preg_match('/\"(.*?)\"/',$file[$i],$m);
        echo $m[1];
        echo "<br>"           ;

//end-title
}
}
//end of article
}



I don't know what is the wrong here. Which is the efficient way to get the value between double quotes as I need.

解决方案

file=file("master.bib");


m=array();


c=count(


这篇关于如何捕获PHP中双引号之间的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆