<a href="http://www.google.com/search?q='.urlencode(current(explode('(', $ask_key))).'" target="_blank">
我不明白urlencode(current(explode('(', $ask_key)))
做什么。
任何人都可以解释我的代码做什么?这段代码做了什么?
<a href="http://www.google.com/search?q='.urlencode(current(explode('(', $ask_key))).'" target="_blank">
我不明白urlencode(current(explode('(', $ask_key)))
做什么。
任何人都可以解释我的代码做什么?这段代码做了什么?
$array
为string,它必须包含几个值,用(
分隔。
explode()
会将此字符串拆分为array,并使用(
作为分隔符。
current()
将获取数组的当前元素 - 第一个。
最后,urlencode()
将对特殊字符进行编码,以便它们可以在URL中使用。
因此,基本上:
these(are(elements
urlencode
功能,因此它可以在URL中使用。
作为一个例子,这里是相同种类的代码,分割成几个不同的操作,使用一个变量来存储每个函数的结果 - 所以我们可以转储这些结果:
$string = "[email protected]?i&s(a couple(of elements";
var_dump($string);
$array = explode('(', $string);
var_dump($array);
$first_item = current($array);
var_dump($first_item);
$encoded = urlencode($first_item);
var_dump($encoded);
四个var_dump()
会给这个输出:
string '[email protected]?i&s(a couple(of elements' (length=30)
array
0 => string '[email protected]?i&s' (length=9)
1 => string 'a couple' (length=8)
2 => string 'of elements' (length=11)
string '[email protected]?i&s' (length=9)
string 'th%40is%3Fi%26s' (length=15)
这都说明在细节你的表情的每一个部分呢。
$ask_key = 'as das df(sdfkj as(asf a152451(sdfa df1 9'; //you key
echo $ask_key."<br/>";
$array = explode('(', $ask_key); //explode will split the array on '('
echo "<pre>";
print_r($array);
echo "</pre>";
$curr = current($array); //current will return the curr element of array
echo $curr."<br/>";
$enc = urlencode($curr); //url will encode url i.e. valid url
echo $enc;
结果::
as das df(sdfkj as(asf a152451(sdfa df1 9
Array
(
[0] => as das df
[1] => sdfkj as
[2] => asf a152451
[3] => sdfa df1 9
)
as das df
as+das++df
很好的例子。谢谢。 – enjoylife 2011-03-18 05:45:57
当然欢迎你 – 2011-03-18 05:53:01
粗犷再次胜过简洁:) – webbiedave 2011-03-18 06:55:59