Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

create a php pattern to extract many lines of keywords in a block of text

{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':
words here
{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':

{'id':'13984411111111111','showcode':'Click to copy','copy':'want-this', 'url':

{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':
{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':


in a block of text want many lines of 'want-this'

text
want-this
may be different

but is always surrounded by
','showcode':'Click to copy','copy':'
', 'url':
Avatar of Jagadishwor Dulal
Jagadishwor Dulal
Flag of Nepal image

How do you generate the above text block??
Are you looking for something like this

$line = "{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':";
$pattern = "/^{'id':'[0-9]+','showcode':'Click to copy','copy':'(.*)', 'url':.*$/";
$matches = array();
$result = preg_match($pattern, $line, $matches);
echo "<pre>"';
print_r($matches);
echo "</pre>"';

Open in new window


The text you want should be in $matches[1];
Avatar of rgb192

ASKER

by: julianHPosted on 2013-06-02 at 11:35:24ID: 39214476

works for

$line = "{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':";

but want many lines

$line="
{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':
words here
{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':

{'id':'13984411111111111','showcode':'Click to copy','copy':'want-this', 'url':

{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':
{'id':'139844','showcode':'Click to copy','copy':'want-this', 'url':
";


How do you generate the above text block??

code is html source code
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

both codes get 'want this'

thanks
You are welcome - thanks for the points.
Avatar of rgb192

ASKER

Thank you