Hello
Assuming a string has the value:
onclick="<javascript code here>"
or
onclick='<javascript code here>'
is there an easy method using regular expression to obtain the JavaScript code without resorting to parsing?
onclick is case insensitive and the <javascript code here> may contain double or single quotes, but you can assume it is legal
any help would be appreciated
how to extract the onclick value from a string
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
time to get the regex book, friend.
code is untested.
Code: Select all
preg_match_all('#<\s*\w+.*?\s+onclick\s*=\s*(ї"'']?)(.*?)(\\1).*?>#si', $text, $matches);
print_r($matches);