rgb192
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':
words here
{'id':'139844','showcode':
{'id':'13984411111111111',
{'id':'139844','showcode':
{'id':'139844','showcode':
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':
How do you generate the above text block??
Are you looking for something like this
The text you want should be in $matches[1];
$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>"';
The text you want should be in $matches[1];
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
works for
$line = "{'id':'139844','showcode'
but want many lines
$line="
{'id':'139844','showcode':
words here
{'id':'139844','showcode':
{'id':'13984411111111111',
{'id':'139844','showcode':
{'id':'139844','showcode':
";
How do you generate the above text block??
code is html source code
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
both codes get 'want this'
thanks
thanks
You are welcome - thanks for the points.
ASKER
Thank you