Archive for 12月, 2011
PHP Get 方法加号处理
用 get 方法 , 参数里有 “+” 时,要做处理,否则到后台会变成空格
解决方案:
1 、改用 post 方法 ,ok
2 、在 js 里用 url = encodeURI(encodeURI(XXX))
3 、将参数里的加号进行转换 data = data.replace(/\+/g, “%2B”);
(2,3步可以合为一步 encodeURIComponent(encodeURIComponent(xxxx)) )
4、 PHP接受使用 rawurldecode后台再解码一次, ok
Ubuntu Linux下为PHP5安装cURL
开启curl也好,加装curl也好,都是一码事。本文假定你的Ubuntu Linux已经安装好了LAMP环境。
先查看自己的php5是否已经安装了curl。方法如下:
1.在web服务器目录( Ubuntu下的通常为 /var/www )新建test.php文件
2.编辑文件,键入下面一行代码:
3.保存文件
4.打开浏览器,浏览该网页。(例如:http://localhost/test.php)
5.搜索”curl”,看看是否已经安装了curl。没搜到的话肯定是没装了,要装的请看下面。
安装方法很简单,只需要一条命令。(这里选择直接apt-get安装,因为比起自己编译简单多了,不需要自己配置什么)
# sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
恭喜,PHP5 cURL安装完毕。记得重启Apache服务器
# sudo /etc/init.d/apache2 restart
如果仍然有问题,尝试编辑你的php.ini文件(我的是/etc/php5/apache2/php.ini),在最后加上一行:
extension=curl.so
保存文件后重启Apache服务器。
Using OpenGraph with PHP (cUrl requests for actions)
When I press the “get code” link near the action, that’s what I get:
curl -F ‘access_token=***’ \
-F ‘article=http://example.com’ \
‘https://graph.facebook.com/me/yellowheart:read’
(There’s an actual access token of course).
sing the PHP SDK you would use the api method.
$facebook = new Facebook($config);
…
$facebook->api(‘https://graph.facebook.com/me/yellowheart:read?
article=http://example.com”,’POST‘);
You could also do a raw request
$myurl = [...]
