我只需要从html 中提取client_token
值。这是我迄今为止的尝试
preg_match("#var client_token(.*)=(.*)'(.*?)'#is", $html, $match);
使用 \\s+ 而不是 .* 以避免匹配随机内容:
preg_match("#var client_token\s*=\s*'(.*?)'#is", $html, $match);
If the html code is constant you can use bottom code.
preg_match("/var client_token = '(.*?)';/", $html, $match);
But if space
and qoute
is unknown use this
preg_match("/var\s+client_token\s*=\s*[\'|\"](.*?)[\'|\"]\s*;/", $html, $match);
\\s+
match one/multiple space \\s*
match none/one/multiple space ['|"]
match '
or "
This is the most compact and easy to understand:
preg_match("/client_token[^\']*\'([^\']*)/", $html, $match);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.