转义字符 [英] Escape character

查看:33
本文介绍了转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能:

<?php
function getmypost($number)
    {
        query_posts('p=1828');
        while (have_posts()) : the_post();
        the_title('<h1>', '</h1>');
        the_content();
        endwhile;
    }
?>

我需要将 1828 作为变量我试过这个:

I need to make the 1828 as a variable I have tried this:

    query_posts('\'p='. $number .'\'');

但它不起作用.这样做的正确方法是什么?

But it does not work. What would be the right way to do this?

推荐答案

如果我理解正确

query_posts('p='.$number);

应该可以.

如果您需要在字符串中使用单引号 ',您可以转义 '

If you need a single quote ' in the string you'd escape the '

query_posts('p=\''.$number.'\'');

或者使用双引号(更优雅,你可以直接输入变量.Dominik 已经在他的回答中提出了这一点)

or using double quotes (more elegant, and you can put the variable straight in. Dominik already suggested this in his answer)

query_posts("p='$number'");

这篇关于转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆