- PHP code
$str="http://www.baidu.com/s?wd=js%E8%8E%B7%E5%8F%96php%E5%8F%98%E9%87%8F&tn=ichuner_1_dg&ie=utf-8"; preg_match("/(?:baidu.+?wd=|baidu.+?kw=|baidu.+?word=|soso.+?w=|sogou.+?query=|bing.+?q=|114.+?kw=)([^&]*)/i",$str,$matches); $keystr=urldecode($matches[1]);
------解决方案--------------------
- JScript code
$str="http://www.baidu.com/s?wd=js%E8%8E%B7%E5%8F%96php%E5%8F%98%E9%87%8F&tn=ichuner_1_dg&ie=utf-8"; var re = /(?:baidu.+?wd=|baidu.+?kw=|baidu.+?word=|soso.+?w=|sogou.+?query=|bing.+?q=|114.+?kw=)([^&]*)/i alert($str.match(re)[1])
------解决方案--------------------
- JScript code
<script> var str = "http://www.baidu.com/s?wd=js%E8%8E%B7%E5%8F%96php%E5%8F%98%E9%87%8F&tn=ichuner_1_dg&ie=utf-8"; var matches = str.match(/(?:baidu.+?wd=|baidu.+?kw=|baidu.+?word=|soso.+?w=|sogou.+?query=|bing.+?q=|114.+?kw=)([^&]*)/i); var keystr = decodeURI(matches[1]); alert(keystr) </script>