开发者

Escape character

开发者 https://www.devze.com 2022-12-19 14:58 出处:网络
I have this function : <?php function getmypost($number) { query_posts(\'p=1828\'); while (have_posts()) : the_post();

I have this function :

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

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?


If I understand you correctly

query_posts('p='.$number);

should work.

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

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

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'");


You could use

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

精彩评论

暂无评论...
验证码 换一张
取 消