php file_get_contents读取远程文件并输出
php file_get_contents读取远程文件并输出,这样做的好得就是不会在flash播放代码中显示对方网站的文件地址,下面是我自己用的一个.是读取方视频文件用的.
<?php
require_once("s/s.php");
$a_id =get_value('id','');
if(is_numeric($a_id) ){
$result =mysql_query("Select * from s where id='$a_id'") or die(mysql_error());
if( mysql_num_rows($result) ){
$rs =mysql_fetch_array( $result );
$swfpath=$rs[5];
}
}
function Get_swf($url){
$data = file_get_contents($url);
header("content-type: application/x-shockwave-flash");
echo $data;
}
?>
本站原创: www.111cn.net 转载请注明来处.
<?php
PHP代码:
<?php
$page_info = count_page($total , PER_PAGE );//分页参数
$smarty->assign('page_first' , $page_info['page_first']);
$smarty->assign('page_last' , $page_info['page_last']);
$smarty->assign('page_str' , $page_info['page_str']);
$sql = "SELECT * FROM `news` ORDER BY `id` DESC LIMIT {$page_info['offset']} , " . PER_PAGE;
?>
//PAGE : $total总页数 $per每页显示条数 $show 列表条数
function count_page($total = 0 , $per )
{
$page_out = array(
'page_first' => '', //首页
'page_last' => '', //末页
'page_str' => '' , //分页
'now_page' => 1 , //当前页
'offset' => 0, //偏移量
);
$page_count = ceil($total / $per); //总页数
if($page_count <= 1){
return $page_out;
}
$page_out['now_page'] = @$_GET['page'] + 0;
if($page_out['now_page'] < 1){
$page_out['now_page'] = 1;
} elseif($page_out['now_page'] > $page_count){
$page_out['now_page'] = $page_count;
}
$page_out['offset'] = ($page_out['now_page'] - 1) * $per;
//URL正则
$SELF = "[url=http://{$_SERVER[]http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF'[/url]]}?";
@$QUERY = $_SERVER['QUERY_STRING'];
$query_page = preg_replace(array("!((&|^)page=([^&]+))|(page=)!" , "!(^&)|[&]{2,}|([&]$)!") , array('' , '') , $QUERY);
$query_page = $SELF . $query_page . ($query_page ? "&" : "");
/*first page*/
$page_out['page_first'] = '1';
if($page_out['page_first'] == $page_out['now_page']){
$page_out['page_first'] = '<li class="previous-off"><<首页</li>';
}else{
$page_out['page_first'] = '<li><a href="?page=1"><<首页</a></li>';
}
/*last page*/
$page_out['page_last'] = $page_count;
if($page_out['page_last'] == $page_out['now_page']){
$page_out['page_last'] = '<li class="next-off"">尾页>></li>';
}else{
$page_out['page_last'] = '<li><a href="?page=' . $page_count. '">尾页>></a></li>';
}
//限制分页 2008-6-2 Edit
$pageleft = $page_out['now_page'] >= 4 ? $page_out['now_page'] - 4 : 1;
$pageright = $page_out['now_page'] + 4 <= $page_count ? $page_out['now_page'] + 4 : $page_count;
for($i = $pageleft; $i <= $pageright; $i++) {
if($i == $page_out['now_page']){
$page_out['page_str'] .= '<li class="active">' . $i . '</li>';
} else {
$page_out['page_str'] .= '<li><a href="' . $query_page . 'page=' . $i . '">' . $i . '</a></li>';
}
}
return $page_out;
}
?>
复制PHP内容到剪贴板
PHP代码:
CSS 文件
/*PAGE*/
#page li { border:0; margin:0; padding:0; font-size:11px; list-style:none; /* savers */ float:left; }
#page a { border:solid 1px #9aafe5; margin-right:2px; }
#page .previous-off,#page .next-off { border:solid 1px #DEDEDE; color:#888888; display:block; float:left; font-weight:bold; margin-right:2px; padding:3px 4px; }
#page .next a,#page .previous a { font-weight:bold; }
#page .active { background:#2e6ab1; color:#FFFFFF; font-weight:bold; display:block; float:left; padding:4px 6px; /* savers */ margin-right:2px; }
#page a:link,#page a:visited { color:#0e509e; display:block; float:left; padding:3px 6px; text-decoration:none; }
#page a:hover{ border:solid 1px #0e509e; }
require_once('cls.small_editor.php');
$obj = new SmallEditor();
$obj -> setEditor($e_form_name,$e_form_value,$width,$height);
<?php
/*===========================================================
= 版权协议:
= GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
=------------------------------------------------------------
= 文件名称:cls.small_editor.php
= 摘 要:轻量级HTML编辑器 for PHP5
= 版 本:1.0
=------------------------------------------------------------
= Script Written By phpwms项目组
= 最后更新:xinge
= 最后日期:2008-07-24
============================================================*/
!defined('IN_SYS') and die('Hacking attempt');
class SmallEditor {
public $editor_dir = 'editor/SMALLeditor/';
public function __construct() {
global $root_dir;
$this -> editor_dir = $root_dir.$this -> editor_dir;
ob_start(array($this,'callBack'));
}
// 初始化
private function editorInit() {
$str = '<link rel="stylesheet" type="text/css" href="'.$this -> editor_dir.'comm.css" />'."\n";
$str .= '<script type="text/javascript" language="JavaScript" src="'.$this -> editor_dir.'all.js"></script>'."\n";
$str .= '<script type="text/javascript" language="JavaScript" src="'.$this -> editor_dir.'editor.js"></script>'."\n";
$str .= '<script type="text/javascript" language="JavaScript" src="'.$this -> editor_dir.'editor_toolbar.js"></script>'."\n";
return $str;
}
// 回调替换
public function callBack($buffer) {
return (str_replace(array('</HEAD>','</Head>','</head>'),$this -> editorInit().'</HEAD>', $buffer));
}
public function setEditor($e_form_name = 'my_text_area',$e_form_value = '',$e_toolbar = 'AdminMode',$height='',$width = '100%') {
!$height and $height = 230;
!strstr($height,'%') and $height = $height.'px';
!strstr($width,'%') and $width = $width.'px';
return <<<EOF
<textarea id="{$e_form_name}" name="{$e_form_name}" style="display:none;">{$e_form_value}</textarea>
<script language="javascript">
gContentId = "{$e_form_name}";
OutputEditorLoading();
</script>
<iframe id="HtmlEditor" class="editor_frame" frameborder="0" marginheight="0" marginwidth="0" style="width:{$width};height:{$height};overflow:visible;" hideFocus></iframe>
EOF;
}
}
?>新浪编辑器的调用
+----------------------------------------------------------
* @param mixed $where 数据
* @param string $tables 数据表名
* @param string $fields 字段名
* @param string $order 排序
* @param string $limit
* @param string $group
* @param string $having
* @param boolean $cache 是否缓存
* @param boolean $lazy 是否惰性加载
* @param boolean $lock 是否加锁
+----------------------------------------------------------
* @return ArrayObject
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function find($where,$tables,$fields='*',$order=null,$limit=null,$group=null,$having=null,$join=null,$cache=false,$lazy=false,$lock=false)
{
if(in_array($this->getDbType(),array('MSSQL','IBASE'),true) ) {
$this->queryStr = 'SELECT '.$this->parseLimit($limit)
.$this->parseFields($fields)
.' FROM '.$tables
.$this->parseJoin($join)
.$this->parseWhere($where)
.$this->parseGroup($group)
.$this->parseHaving($having)
.$this->parseOrder($order);
}else{
$this->queryStr = 'SELECT '.$this->parseFields($fields)
.' FROM '.$tables
.$this->parseJoin($join)
.$this->parseWhere($where)
.$this->parseGroup($group)
.$this->parseHaving($having)
.$this->parseOrder($order);
if("ORACLE" == $this->getDbType())
if($limit[0] <= 0){
if($limit[1] > 0)
$this->queryStr = "SELECT * FROM (".$this->queryStr.") WHERE ROWNUM <= ".$limit[1];
}else{
$whereClause = "";
if($limit[1] > 0)
$whereClause = " WHERE ROWNUM <= ".($limit[0] + $limit[1]);
$this->queryStr = "SELECT * FROM ( SELECT ROW_.*, ROWNUM ROWNUM_ FROM ("
.$this->queryStr.") ROW_"
.$whereClause
.") WHERE ROWNUM_ > "
.$limit[0];
}
else
$this->queryStr .= $this->parseLimit($limit);
}
return $this->query('',$cache,$lazy,$lock);
}
jquery与 ajax 简单例子
基于JQuery框架的AJAX
PS:本人这篇始发于PHPCHINA,发现被很多人转了,但却未注明出处,想了一下,还是自己转到这里来。
前几天发了个贴,分享了prototype框架关于AJAX方面的学习过程。然后有人说jquery框架更方便。
正好项目中准备使用thickbox,于是干脆抛弃prototype.js,看起jquery.js了。JQuery确实不错,体积比Prototype小了许多,而且使用起来更方便更灵活。有人说Prototype像JAVA,正统;而JQuery像Ruby,灵活,更趋于OOP。
小试了下AJAX,感觉比prototype简洁多了,在JQuery中,AJAX有三种实现方式:$.ajax(),$.post,$.get()。
XHTML(主要):
代码: 复制内容到剪贴板
<div id="result" style="backgroundrange;border:1px solid red;width:300px;height:400px;"></div>
<form id="formtest" action="" method="post">
<p><span>输入姓名:</span><input type="text" name="username" id="input1" /></p>
<p><span>输入年龄:</span><input type="text" name="age" id="input2" /></p>
<p><span>输入性别:</span><input type="text" name="sex" id="input3" /></p>
<p><span>输入工作:</span><input type="text" name="job" id="input4" /></p>
</form>
<button id="send_ajax">提交</button>
<button id="test_post">OST提交</button>
<button id="test_get">GET提交</button>
JS:
1、引入jquery框架:
代码: 复制内容到剪贴板
<script type="text/javascript" src="../js/jquery.js"></script>
2、构建AJAX,JQUERY的好处是不需要在XHTML中使用JS代码来触发事件了,可以直接封装在JS文件中:
代码: 复制内容到剪贴板
<script type="text/javascript">
//$.ajax()方式
$(document).ready(function (){
$('#send_ajax').click(function (){ //直接把onclick事件写在了JS中,而不需要混在XHTML中了
var params=$('input').serialize(); //序列化表单的值,与prototype中的form.serialize()相同
$.ajax({
url :'ajax_test.php', //后台处理程序
type:'post', //数据发送方式
dataType:'json', //接受数据格式
data:params, //要传递的数据
success:update_page //回传函数(这里是函数名)
});
});
});
function update_page (json) { //回传函数实体,参数为XMLhttpRequest.responseText
var str="姓名:"+json.username+"";
str+="年龄:"+json.age+"";
str+="性别:"+json.sex+"";
str+="工作:"+json.job;
$("#result").html(str);
}
//$.post()方式:
$(function (){//$(document).ready(function (){ 的简写
$('#test_post').click(function (){
$.post('ajax_test.php',
{username('#input1').val(),age('#input2').val(),sex('#input3').val(),job('#input4').val()},
function (data){ //回传函数
var myjson='';
eval('myjson='+data+';');
$('#result').html("姓名:"+myjson.username+"
工作:"+myjson['job']);
});
});
});
$.get()方式:
$(function (){
$('#test_get').click(function (){
$.get('ajax_test.php',
{username("#input1").val(),age("#input2").val(),sex("#input3").val(),job("#input4").val()},
function (data) {
var myjson='';
eval("myjson="+data+";");
$("#result").html(myjson.job);
});
});
});
</script>
PHP代码:
代码: 复制内容到剪贴板
<?php
$arr=$_POST; //若以$.get()方式发送数据,则要改成$_GET.或者干脆_REQUEST
$myjson=json_encode($arr);
echo $myjson;
?>
相关文章
php 中file_get_contents超时问题的解决方法
file_get_contents超时我知道最多的原因就是你机器访问远程机器过慢,导致php脚本超时了,但也有其它很多原因,下面我来总结file_get_contents超时问题的解决方法总结。...2016-11-25- 这篇文章主要介绍了C#从数据库读取图片并保存的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2021-01-16
php file_get_contents 设置代理抓取页面示例
file_get_contents函数在php中可以直接打开本地文件也可以直接抓取远程服务器文件,如果简单的采集我们可以使用file_get_contents直接来操作,如果有防采集我们可能需要...2016-11-25- 在php中解析xml文档用专门的函数domdocument来处理,把json在php中也有相关的处理函数,我们要把数据xml 数据存到一个数据再用json_encode直接换成json数据就OK了。...2016-11-25
php报错file_get_contents(): php_network_getaddresses问题
本文章来为各位介绍一篇关于file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known...错误解决办法。 昨天,服务器的DN...2016-11-25- file_get_contents的超时处理话说,从PHP5开始,file_get_content已经支持context了(手册上写着:5.0.0 Added the context support. ),也就是说,从5.0开始,file_get_contents其实也可以POST数据。今天说的这篇是讲超时的,确实在...2013-10-04
- 这篇文章主要介绍了c# 如何对CSV文件操作,帮助大家更好的理解和学习C#,感兴趣的朋友可以了解下...2020-11-03
- 本文主要介绍了python读取和保存mat文件的方法,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-08-25
file_get_contents()获取https出现这个错误Unable to find the wrapper “https”
下面我们来看一篇关于file_get_contents()获取https出现这个错误Unable to find the wrapper “https”问题的解决办法. file_get_contents()获取https出现这个错...2016-11-25- 首先如果要在程序中使用sdcard进行存储,我们必须要在AndroidManifset.xml文件进行下面的权限设置: 在AndroidManifest.xml中加入访问SDCard的权限如下: <!--...2016-09-20
- perl CPAN中有一个Tie-File 模块极大方便了对大文件的操作...2020-06-29
使用MSScriptControl 在 C# 中读取json数据的方法
下面小编就为大家带来一篇使用MSScriptControl 在 C# 中读取json数据的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25- 这篇文章主要介绍了C#实现appSettings节点读取与修改的方法,是非常实用的技巧,需要的朋友可以参考下...2020-06-25
- 在使用file_put_contents时会碰到并发性问题了,对于这个问题我们有多种解决方案了,其实锁是小编比较喜欢的解决办法了,当然也有其它办法,具体如下。 解决 办法一,fil...2016-11-25
php提示Warning: file_get_contents(): couldn’t resolve
在使用file_get_contents函数获取远程文件时提示Warning: file_get_contents(): couldn’t resolve错误了,这个我们可以看出是dns的问题,解决办法也简单。 今天在...2016-11-25- 这篇文章主要介绍了golang文件读取-按指定BUFF大小读取方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-12-22
- 本文主要介绍了Java读取PDF中的表格的方法示例,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-10-22
- 这篇文章主要介绍了R语言读取csv文件出错的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-05-06
- 下在看一个利用fopen,file_get_contents读取本地服务器中.php文件的代码并显示的一些方法总结 如我有两个文件a.php,b.php。 a.php文件中的语句是: 代码如...2016-11-25
- 这篇文章主要介绍了Windows系统中使用C#读取文本文件内容的小示例,包括一次一行地读取文本文件的方法,需要的朋友可以参考下...2020-06-25