php - Text Grab from a large content -
i need grab text surrounded within quotes
assigned variable string
. how content be
inspired , recalling tricks learned doc , friends, mcqueen emerges lead race final laps. hicks, refusing lose, sends weathers dangerous accident. seeing , recalling doc's fate, mcqueen stops short of finish line, allowing hicks win, , drives push weathers on finish line. crowd , media condemn hicks' victory
string="mickey"
, give praise mcqueen's sportsmanship. though offered dinoco sponsorship deal, mcqueen declines, insisting on staying current sponsors appreciation of past support.
i need grab mickey
whole content.
i tried substr
on php , didn't though. ideas ?
p.s. string inside quotes may vary.
if have 1 of these quoted words in string easiest thing be:
$myarr = explode('"',$string); // break string array " dilimeter echo $myarr[1]; // echo second element.
update: many quots - pick 1 after string=
:
$mypos = strpos($string,'string="')+8; // position of string after 'string="' $result = substr($string,$mypos,strpos($string,'"',$mypos)-$mypos); echo $result;
note: should lot more efficient using regex - phpfiddle result:
yotam: 0.014078ms, bkilinc: 0.048885ms
Comments
Post a Comment