Escape symbol

I have this function:

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

I need to make 1828 as a variable. I tried this:

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

But that will not work. What would be the right way to do this?

0
string php var
Feb 10 '10 at 15:00
source share
2 answers

If I understand you correctly

 query_posts('p='.$number); 

must work.

If you need a single quote ' per line, you can escape '

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

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

 query_posts("p='$number'"); 
+3
Feb 10 '10 at 15:01
source share

you can use

 query_posts("'p=$number'"); 
0
Feb 10 '10 at 15:05
source share



All Articles