Reputation: 10581
How do I write a regex to extract the "desired text" from the following:
data-zoom-image="desired text"
Upvotes: 0
Views: 63
Reputation: 32730
$str = 'data-zoom-image="desired text"';
preg_match('/data-zoom-image="(?P<text>\w+)"/', $str, $matches);
print_r($matches);
ref: http://php.net/manual/en/function.preg-match.php
Upvotes: 0
Reputation:
without quota:
substr($text, strpos($text, '"')+1, strrpos($text, '"') - strpos($text, '"')-1) ;
Upvotes: 0
Reputation: 29912
You don't need a preg_match
for do this operation.
Simply you could use a substr in tandem with strpos
$find = substr($yourString,strpos($yourString,"="));
Upvotes: 1
Reputation: 1365
preg_match('/(data-zoom-image=")(.*)(")/',$youstring,$match);
echo $match[2];
try this. it is a pattren
Upvotes: 1