php怎么允许短标签?PHP短标签开启设置实例代码

 更新时间:2017年7月6日 23:50  点击:1816
php怎么允许短标签?本文介绍的是PHP短标签开启设置实例代码,对初学php的同学很有帮助。

代码如下:

//php.ini中
short_open_tag = On

//除,可使用更灵活的调用方法

本文介绍了php运行一个url的教程,不会的同学可以参考一下本文,过程非常简单

PHP:

header('Location: http://www.example.com/');

file_get_contents(http://it.sohu.com/7/1002/17/column20466721_3257.shtml);

小编推荐的这篇文章介绍了php存储过程调用实例代码,不知道php怎么运行存储过程的同学可以参考一下,一定会很有收获。

代码如下:

 代码如下复制代码
//比如要调用的存储过程为gxtj(a,b) 
$db=new mysqli("localhost","ssss","aaaaa","bbbb"); 
mysqli_query($db,"SET NAMES utf8"); 
$result=$db->query("call gxtj($year,$jd)"); // gxtj是mysql的存储过程名称 [color=gray][/color] 
while( $row = $result->fetch_array(MYSQLI_ASSOC)) //完成从返回结果集中取出一行 

while ($key=key($row)){ //依次取得字段名 
$value=current($row); //依次取得字段值 

实例一:无参的存储过程

 代码如下复制代码
$conn = mysql_connect('localhost','root','root') or die ("数据连接错误!!!");
mysql_select_db('test',$conn);
$sql = "
create procedure myproce()
begin
INSERT INTO user (id, username, sex) VALUES (NULL, 's', Ɔ');
end; 
";
mysql_query($sql);//创建一个myproce的存储过程

$sql = "call test.myproce();";
mysql_query($sql);//调用myproce的存储过程,则数据库中将增加一条新记录。

 

实例二:传入参数的存储过程

 代码如下复制代码
$sql = "
create procedure myproce2(in score int)
begin
if score >= 60 then
select 'pass'
else
select 'no'
end if;
end; 
";
mysql_query($sql);//创建一个myproce2的存储过程
$sql = "call test.myproce2(70);";
mysql_query($sql);//调用myproce2的存储过程,看不到效果,可以在cmd下看到结果。

实例三:传出参数的存储过程

 代码如下复制代码
$sql = "
create procedure myproce3(out score int)
begin
set score=100;
end; 
";
mysql_query($sql);//创建一个myproce3的存储过程
$sql = "call test.myproce3(@score);";
mysql_query($sql);//调用myproce3的存储过程
$result = mysql_query('select @score;');
$array = mysql_fetch_array($result);
echo '
'print_r($array);

实例四:传出参数的inout存储过程

 代码如下复制代码
$sql = "
create procedure myproce4(inout sexflag int)
begin
SELECT * FROM user WHERE sex = sexflag;
end; 
";
mysql_query($sql);//创建一个myproce4的存储过程
$sql = "set @sexflag = 1";
mysql_query($sql);//设置性别参数为1
$sql = "call test.myproce4(@sexflag);";
mysql_query($sql);//调用myproce4的存储过程,在cmd下面看效果

实例五:使用变量的存储过程

 代码如下复制代码
$sql = "
create procedure myproce5(in a int,in b int)
begin
declare s int default 0;
set s=a+b;
select s;
end; 
";
mysql_query($sql);//创建一个myproce5的存储过程
$sql = "call test.myproce5(4,6);";
mysql_query($sql);//调用myproce5的存储过程,在cmd下面看效果

实例六:case语法

 代码如下复制代码
$sql = "
create procedure myproce6(in score int)
begin
case score
when 60 then select '及格'
when 80 then select '及良好'
when 100 then select '优秀'
else select '未知分数'
end case;
end; 
";
mysql_query($sql);//创建一个myproce6的存储过程
$sql = "call test.myproce6(100);";
mysql_query($sql);//调用myproce6的存储过程,在cmd下面看效果

实例七:循环语句

 代码如下复制代码
$sql = "
create procedure myproce7()
begin
declare i int default 0;
declare j int default 0;
while i<10 do
set j=j+i;
set i=i+1;
end while;
select j;
end; 
";
mysql_query($sql);//创建一个myproce7的存储过程
$sql = "call test.myproce7();";
mysql_query($sql);//调用myproce7的存储过程,在cmd下面看效果

实例八:repeat语句

 代码如下复制代码
$sql = " 
create procedure myproce8()
begin
declare i int default 0;
declare j int default 0;
repeat
set j=j+i;
set i=i+1;
until j>=10
end repeat;
select j;
end; 
";
mysql_query($sql);//创建一个myproce8的存储过程
$sql = "call test.myproce8();";
mysql_query($sql);//调用myproce8的存储过程,在cmd下面看效果

实例九:loop语句

 代码如下复制代码
$sql = "
create procedure myproce9()
begin
declare i int default 0;
declare s int default 0;

loop_label:loop
set s=s+i;
set i=i+1;
if i>=5 then
leave loop_label;
end if;
end loop;
select s;
end; 
";
mysql_query($sql);//创建一个myproce9的存储过程
$sql = "call test.myproce9();";
mysql_query($sql);//调用myproce9的存储过程,在cmd下面看效果

 

实例十:删除存储过程

 

 代码如下复制代码
mysql_query("drop procedure if exists myproce");//删除test的存储过程
实例十:存储过程中的游标
总结中。

 

php怎么运行c语言程序?本文介绍了利用php调用C语言 扩展PHP的功能的教程,对php初学者来说非常有用,有兴趣的同学快看看吧!

第一步. 生成需要调用的so文件

1.  首先做一个简单的so文件:

/** * hello.c

* To compile, use following commands:

 *   gcc -O -c -fPIC -o hello.o hello.c

  *   gcc -shared -o libhello.so hello.o

*/

int hello_add(int a, int b)

{

    return a + b;

}

然后将它编译成.so文件并放到系统中:

$ gcc -O -c -fPIC -o hello.o hello.c                      // -fPIC:是指生成的动态库与位置无关

$ gcc -shared -o libhello.so hello.o                     // -shared:是指明生成动态链接库

$ su        // 切换成超级用户,此时,需要输入密码。

# cp libhello.so /usr/local/lib      // 把生成的链接库放到指定的地址

# echo /usr/local/lib > /etc/ld.so.conf.d/local.conf       //  把库地址写入到配置文件中

# /sbin/ldconfig                // 用此命令,使刚才写的配置文件生效

2. 写段小程序来验证其正确性:

/**

 * hellotest.c

 * To compile, use following commands:

*   gcc -o hellotest -lhello hellotest.c

*/

#include

int main()

{

    int a = 3, b = 4;

    printf("%d + %d = %d", a, b, hello_add(a,b));

    return 0;

}

编译并执行:

$ gcc -o hellotest -lhello hellotest.c                // 编译测试文件,生成测试程序

$ ./hellotest           // 运行测试程序

第二步. 制作PHP模块(外部模块)

请确保你已安装 PHP及APACHE服务器。

$ cd php-5.2.3/ext

1. 然后通过下面的命令用ext_skel脚本建立一个名为 hello 的模块:

$ ./ext_skel --extname=hello

2. 执行该命令之后它会提示你应当用什么命令来编译模块,可惜那是将模块集成到php内部的编译方法。

如果要编译成可动态加载的 php_hello.so,方法要更为简单。

$ cd hello

 首先编辑 config.m4 文件,去掉第16行和第18行的注释(注释符号为 dnl 。)

16:  PHP_ARG_ENABLE(hello, whether to enable hello support,

17:  dnl Make sure that the comment is aligned:

18:  [  --enable-hello           Enable hello support])

3. 然后执行 phpize 程序,生成configure脚本:

$ phpize

 该程序在ubuntu的php5-dev包中

4. 打开 php_hello.h,在 PHP_FUNCTION(confirm_hello_compiled); 之下加入函数声明:

PHP_FUNCTION(confirm_hello_compiled);   /* For testing, remove later. */

PHP_FUNCTION(hello_add);

5. 打开 hello.c,在 PHP_FE(confirm_hello_compiled, NULL) 下方加入以下内容。

zend_function_entry hello_functions[] = {

    PHP_FE(confirm_hello_compiled,  NULL)       /* For testing, remove later. */

    PHP_FE(hello_add,   NULL)       /* For testing, remove later. */

    {NULL, NULL, NULL}  /* Must be the last line in hello_functions[] */};

    然后在 hello.c 的最末尾书写hello_add函数的内容: 

PHP_FUNCTION(hello_add)

{

    long int a, b;

    long int result;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &a, &b) == FAILURE) {

        return;

    }

    result = hello_add(a, b);

    RETURN_LONG(result);}保存退出,编译并安装:

6. $ ./configure

$ make LDFLAGS=-lhello

$ sudo make install

Installing shared extensions:     /usr/lib/php5/20060613+lfs/$ su# cp modules/hello.so/usr/lib/php/modules

luther@gliethttp:~$ sudo vim /etc/php5/apache2/php.ini;

enable_dl = Off;允许dl()动态加载so扩展功能enable_dl = On

luther@gliethttp:~$ sudo service apache2 reload    然后在 /var/www/html 下建立一个 hello.php 文件,内容如下:

<?php

    dl("hello.so");

    echo hello_add(3, 4);

?>

然后在浏览器中打开hello.php文件,如果显示7,则说明函数调用成功了。

第三步. 制作PHP模块(内部模块)

另外可以在apache重启的时候让我们的so库直接动态编译进php5,就像linux的insmod hello.ko模块一样,不用dl加载也不用重新编译php,就可以直接使用so的函数了,步骤如下:

luther@gliethttp:~$ sudo vim /etc/php5/apache2/php.ini
enable_dl = Off
extension=hello.so
luther@gliethttp:~$ sudo service apache2 restart

不能reload而必须restart apache,这样so就像insmod hello.ko一样被融到了php5内核,然后代码就可以忽略掉dl("hello.so");了,

[注意,这种方式只适合hello.so库内所有功能代码已经全部调试ok,如果还处在调试期间,那么需要采用上面的dl强制加载的方式]

代码如下:

<?php

    echo hello_add(3, 4);

?>,

     但是该功能不太适合调试,因为每次修改hello.so中代码的话,都需要让service apacherestart重启才能让php5内核再次加载新的hello.so扩展.可以这样定义hello.so的实现,这样每次执行.php网页,都会在/var/www/下建立一个文件夹,所以php扩展实现了

一,搭建php环境
下载php 5.2.6 源码 并解压
编译安装,搭建php环境
二,创建扩展项目
进入源码目录
cd php5.2.6/ext/
./ext_skel --extname=my_ext
创建名字为my_ext的项目,最终会生成my_ext.so
三,更改配置和程序
$ vi ext/my_ext/config.m4
根据你自己的选择将
dnl PHP_ARG_WITH(my_ext, for my_ext support,
dnl Make sure that the comment is aligned:
dnl [ --with-my_ext Include my_ext support])
修改成
PHP_ARG_WITH(my_ext, for my_ext support,
Make sure that the comment is aligned:
[ --with-my_ext Include my_ext support])
或者将
dnl PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
dnl Make sure that the comment is aligned:
dnl [ --enable-my_ext Enable my_ext support])
修改成
PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
Make sure that the comment is aligned:
[ --enable-my_ext Enable my_ext support])
$ vi ext/my_ext/php_my_ext.h

PHP_FUNCTION(confirm_my_ext_compiled); /* For testing, remove later. */
更改为
PHP_FUNCTION(say_hello);
$ vi ext/my_ext/my_ext.c

zend_function_entry php5cpp_functions[] = {
PHP_FE(confirm_my_ext_compiled, NULL) /* For testing, remove later. */
{NULL, NULL, NULL} /* Must be the last line in php5cpp_functions[] */
};
更改为
zend_function_entry php5cpp_functions[] = {
PHP_FE(say_hello, NULL)
{NULL, NULL, NULL} /* Must be the last line in php5cpp_functions[] */
};
在最后添加:
PHP_FUNCTION(say_hello)
{
zend_printf("hello world\n");
}
四,编译
$ cd my_ext
$ /usr/local/php/bin/phpize
ps: 如果出现:Cannot find autoconf.……的错误信息,则需要安装 autoconf (安装过程略)
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make
这时会编译出 my_ext/modules/my_ext.so
五,配置php.ini
将my_ext.so放入/usr/local/php/ext/目录
$ vi php.ini

修改添加如下:
extension_dir = '/usr/local/php/ext/'
extension=my_ext.so
六,测试
$ vi test.php
<?php
say_hello();
?>
$ /usr/local/php/bin/php test.php
hello world.
则大功告成

下面我来讲讲如何作一个php的扩展
首先要有一个搭建好的php环境
我把php的安装在了/usr/local/php当然也通过
php的一个配置php.ini的路径但是要注意了
用这种方法安装的php扩展不能实现
我们在php安装以后的/usr/local/php/bin目录
找到这个文件phpize稍后我们将用到他
他就是个shell脚本你可以用vi phpize来查看他的内容
但是你要注意了这个脚本不是在哪里都可以应用的
[root@ns root]# phpize
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module

[root@ns root]# phpize
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module
你会看到这两种结果实际上你查看了这个脚本
很轻松的就会发现是怎么来处理的
你的模扩展的时候最好
放在/usr/local/src/php-4.3.5/ext下
来执行他你在这里也可以这样/usr/local/php/bin/phpize来执行也可以
phpize来执行

我们在/usr/local/src/php-4.3.5/ext下找到这个工具
来建立一个php扩展的一个框架
[root@ns ext]#cd /usr/local/src/php-4.3.5/ext/
[root@ns ext]# ./ext_skel --extname=jinzhesheng_module
Creating directory jinzhesheng_module
Creating basic files: config.m4 .cvsignore jinzhesheng_module.cphp_jinzhesheng_module.h CREDITS EXPERIMENTAL tests/001.phptjinzhesheng_module.php [done].

To use your new extension, you will have to execute the following steps:

1.  $ cd ..
2.  $ vi ext/jinzhesheng_module/config.m4
3.  $ ./buildconf
4.  $ ./configure --[with|enable]-jinzhesheng_module
5.  $ make
6.  $ ./php -f ext/jinzhesheng_module/jinzhesheng_module.php
7.  $ vi ext/jinzhesheng_module/jinzhesheng_module.c
8.  $ make
执行了这个步骤以后你会看到这样的结果
Repeat steps 3-6 until you are satisfied with ext/jinzhesheng_module/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
这样以后我们会在这个目录下生成一个目录叫jinzhesheng_module
进入这里面我们看看
[root@ns ext]# cd jinzhesheng_module/
[root@ns jinzhesheng_module]# ls
config.m4  EXPERIMENTAL          jinzhesheng_module.php    tests
CREDITS    jinzhesheng_module.c  php_jinzhesheng_module.h

然后我们要修改文件顺序是
configue.m4
jinzhesheng_module.c
php_jinzhesheng_module.h

使用文本编辑器打开config.m4文件,文件内容大致如下:

dnl $Id$d

dnl config.m4 for extension my_module

dnl don't forget to callPHP_EXTENSION(my_module)

dnl Comments in this file start with the string 'dnl'.

dnl Remove where necessary. This file will not work

dnl without editing.

dnl If your extension references something external, use with:

dnl PHP_ARG_WITH(my_module, for my_module support,

dnl Make sure that the comment is aligned:

dnl [  --with-my_module             Include my_module support])

dnl Otherwise use enable:

dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,

dnl Make sure that the comment is aligned:

dnl [  --enable-my_module           Enable my_module support])

if test "$PHP_MY_MODULE" != "no"; then

  dnl If you will not be testing anything external, like existence of

  dnl headers, libraries or functions in them, just uncomment the

  dnl following line and you are ready to go.

  dnl Write more examples of tests here...

  PHP_EXTENSION(my_module, $ext_shared)

Fi

根据你自己的选择将

dnl PHP_ARG_WITH(my_module, for my_module support,

dnl Make sure that the comment is aligned:

dnl [  --with-my_module             Include my_module support])

修改成

PHP_ARG_WITH(my_module, for my_module support,

Make sure that the comment is aligned:

[  --with-my_module             Include my_module support])

或者将

dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,

dnl Make sure that the comment is aligned:

dnl [  --enable-my_module           Enable my_module support])

修改成

PHP_ARG_ENABLE(my_module, whether to enable my_module support,

Make sure that the comment is aligned:

[  --enable-my_module           Enable my_module support])
我这里用了后者
然后保存退出
然后在编辑
Vi my_module.c
将文件其中的下列代码进行修改

/* Every user visible function must have an entry in my_module_functions[].

*/

function_entry my_module_functions[] = {

        PHP_FE(say_hello,       NULL)  /* ?添加着一行代码 */

        PHP_FE(confirm_my_module_compiled,      NULL) /* For testing, remove later. */

        {NULL, NULL, NULL}      /* Must be the last line in my_module_functions[] */

};

在文件的最后添加下列代码

PHP_FUNCTION(say_hello)

{

        zend_printf("hello world\n");

}

保存文件退出

然后我们就可以在这个目录下使用上面的命令了
/usr/local/php/bin/phpize
执行以后会看到下面的
[root@ns jinzhesheng_module]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20020918
Zend Module Api No:      20020429
Zend Extension Api No:   20050606
[root@ns jinzhesheng_module]#
然后执行./configure --enable-jinzhesheng_module --with-apxs=/usr/local/apache/bin/apxs --with-php-config=/usr/local/php/bin/php-config
我们在安装以后的php的bin目录下的可以找到这个文件的
php-config 和phpize
这一步骤一定要注意你的apache的apxs放在哪里了
然后执行make
你会看到出现错误了你重新定义了函数我们前面的
这个你在回头改一下这个文件把原来的函数删除掉在生成的文件里面会有同样的函数
你在加入你的代码
就可以通过了
这个时候会在当前的目录下生成一个目录叫modules他的下面就放着你要的
jinzhesheng_module.so文件
cp modules/jinzhesheng_module.so /usr/local/php/ext/
这里需要你先设置你的php的扩展目录的在
在php.ini里面
通过extension_dir
最后一不是你在php.ini文件中打开这个扩展
extension=jinzhesheng_module.so
然后
重新起动apache
用phpinfo来察看一下ok了

[!--infotagslink--]

相关文章

  • Jquery 获取指定标签的对象及属性的设置与移除

    1、先讲讲JQuery的概念,JQuery首先是由一个 America 的叫什么 John Resig的人创建的,后来又很多的JS高手也加入了这个团队。其实 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用简单的一些代...2014-05-31
  • C# 如何设置label(标签)控件的背景颜色为透明

    这篇文章主要介绍了C# 如何设置label(标签)控件的背景颜色为透明,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2020-12-08
  • matplotlib之pyplot模块坐标轴标签设置使用(xlabel()、ylabel())

    这篇文章主要介绍了matplotlib之pyplot模块坐标轴标签设置使用(xlabel()、ylabel()),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
  • JS创建Tag标签的方法详解

    这篇文章主要介绍了JS创建Tag标签的方法,结合具体实例形式分析了javascript动态操作页面HTML元素实现tag标签功能的步骤与相关操作技巧,需要的朋友可以参考下...2017-06-15
  • C#删除UL LI中指定标签里文字的方法

    这篇文章主要介绍了C#删除UL LI中指定标签里文字的方法,涉及C#针对页面HTML元素进行正则匹配与替换的相关操作技巧,需要的朋友可以参考下...2020-06-25
  • 帝国CMS用灵动标签调用实现各种幻灯(焦点图)效果

    用灵动标签(e:loop)可以实现各种幻灯效果,本节讲解制作幻灯的基本方法。 如本站JS焦点图频道里的大部分幻灯图片效果都可以用灵动标签调用的。 ...2015-12-30
  • 帝国CMS灵动标签调用新闻正文内容第一张图片的方法

    有时候我们在建站的过程当中需要调用内容页中正文的第一张图片(并不是缩略图),这样就会无从下手,但其实对不懂开发的站长是太难了,往往是会用标题图片来取代,下面分享网友们贡献出...2015-12-30
  • 探讨JavaScript标签位置的存放与功能有无关系

    在网页中,我们可以将JavaScript代码放在html文件中任何位置,但一般放在head或body标签里面。一般来说,<script>元素放在哪里与其的功能作用是紧密相关的,通过本文我们一起学习下...2016-01-18
  • jquery实现标签支持图文排列带上下箭头按钮的选项卡

    带上下箭头jquery垂直tab选项卡切换标签,技持左侧列表上下滚动,滚动到底部带信息提示。复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml...2015-03-15
  • PHP正则表达式过滤html标签属性(DEMO)

    这篇文章主要介绍了PHP正则表达式过滤html标签属性的相关内容,实用性非常,感兴趣的朋友参考下吧...2016-05-06
  • C#使用正则表达式过滤html标签

    最近在开发一个项目,其中有需求要求我们把一段html转换为一般文本返回,使用正则表达式是明智的选择,下面小编给介绍下C#使用正则表达式过滤html标签,需要的朋友参考下...2020-06-25
  • 基于mybatis中<include>标签的作用说明

    这篇文章主要介绍了基于mybatis中<include>标签的作用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-20
  • HTML 标签中的 Markdown 使用方法

    Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式,下面我们来看一篇关于HTML 标签中的 Markdown 语法...2016-09-20
  • 帝国CMS灵动标签调用当前父栏目下所有子栏目-支持选中状态/高亮

    帝国CMS实现灵动标签调用当前父栏目下所有子栏目-支持选中状态及当前栏目高亮,支持栏目自定义排序。最适用于内容模板,显示父栏目下的子栏目。 支持静态栏目页与动态栏目页 代...2016-05-19
  • jQuery添加和删除指定标签的方法

    这篇文章主要介绍了jQuery添加和删除指定标签的方法,通过动态的给元素添加删除一个CSS类可以实现此功能,需要的朋友可以参考下...2015-12-18
  • 详解Yii2定制表单输入字段的标签和样式的方法

    这篇文章详细介绍了Yii2定制表单输入字段的标签和样式的教程,有需要的同学可以参考一下,以备不时之需。 Yii2中对于表单和字段的支持组件为ActiveForm和ActiveField...2017-01-22
  • 详解HTML5布局和HTML5标签

    这篇文章主要介绍了HTML5布局和HTML5标签的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-12-08
  • C#利用Label标签控件模拟窗体标题的移动及窗体颜色不断变换效果

    Label标签控件相信对大家来说都不陌生,下面这篇文章主要给大家介绍了关于C#利用Label标签控件模拟窗体标题的移动及窗体颜色不断变换效果的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下。...2020-06-25
  • vue实现标签云效果的示例

    这篇文章主要介绍了vue实现标签云效果的示例,帮助大家更好的理解和使用vue框架,感兴趣的朋友可以了解下...2020-11-10
  • 用PHP写了个 标签 按点击率的 字体大小和颜色的 显示效果

    按标签的点击率来设置标签字体的大小和 颜色本程序没有考虑程序性能和函数封装。。。只想表达这个算法具体代码如下: <?php function showTag($cur=47,$ta...2016-11-25