““
if($page>$total_pages) //Display Link to Final Page only.
{
printf(“<a href=”%s?keywords=%s&limit=%d&page=%d”>FINAL PAGE</a>”,htmlentities($_SERVER[‘PHP_SELF’]),urlencode($keywords),$limit,$total_pages);
}
else
{
$i=1;
while($i<=$total_pages)//Display the Pagination Section.
{
if($i==$page) //Bold the ‘current page’ Link.
{
printf(“<a href=”%s?keywords=%s&limit=%d&page=%d”><b>$i</b></a>”,htmlentities($_SERVER[‘PHP_SELF’]),urlencode($keywords),$limit,$i);
}
else
{
printf(“<a href=”%s?keywords=%s&limit=%d&page=%d”>$i</a>”,htmlentities($_SERVER[‘PHP_SELF’]),urlencode($keywords),$limit,$i);
}
$i++;
}
}
The above is what I got regarding printf-ing the url. Note the htmlentities and urlencode.
Now, let’s convert this to use the “echo” instead replacing the printf. How should it look now ?
printf
echo
printf
echo
htmlentities
urlencode
if($page>$total_pages) //Display Link to Final Page only.
{
printf("<a href="%s?keywords=%s&limit=%d&page=%d">FINAL PAGE</a>",htmlentities($_SERVER['PHP_SELF']),urlencode($keywords),$limit,$total_pages);
}
if($page>$total_pages) //Display Link to Final Page only.
{
printf("<a href="htmlentities($_SERVER['PHP_SELF'])?keywords=urlencode($keywords)&limit=urlencode($limit)&page=urlencode($total_pages)">FINAL PAGE</a>";
}
printf
echo
$self_page = htmlentities($_SERVER['PHP_SELF']);
$keywords=urlencode($keywords);
if($page>$total_pages) //Display Link to Final Page only.
{
echo "<a href="$self_page?keywords=$keywords&limit=$limit&page=$total_pages">FINAL PAGE</a>";
}
else
{
$i=1;
while($i<=$total_pages)//Display the Pagination Section.
{
if($i==$page) //Bold the 'current page' Link.
{
echo "<a href="$self_page?keywords=$keywords&limit=$limit&page=$i"><b>$i</b></a>";
}
else
{
echo "<a href="$self_page?keywords=$keywords&limit=$limit&page=$i">$i</a>";
}
$i++;
}
}
if($page>$total_pages) //Display Link to Final Page only.
{
echo "<a href="htmlentities($_SERVER['PHP_SELF'])" . "?keywords=urlencode($keywords)" . "&limit=urlencode($limit)" . "&page=urlencode($total_pages)" . ">" . 'FINAL PAGE</a>' ";
}
``PHP<i>
</i>if($page>$total_pages) //Display Link to Final Page only.
{
echo "<a href="htmlentities($_SERVER['PHP_SELF'])" . "?keywords=urlencode($keywords)" . "&limit=urlencode($limit)" . "&page=urlencode($total_pages)" . ">" . 'FINAL PAGE</a>' ";
}<i>
</i>
`</CODE>
Corrected verson
<CODE lang="PHP">
`PHP<i>
</i>if ($page>$total_pages) {
echo "<a href=" . htmlentities($_SERVER['PHP_SELF']) . "?keywords=" . urlencode($keywords) . "&limit=" . urlencode($limit) . "&page=" . urlencode($total_pages) . ">FINAL PAGE</a> ";
}<i>
</i>
``
* htmlentities($_SERVER['PHP_SELF'])
echo "<a href=" . htmlentities($_SERVER['PHP_SELF'])
<i>
</i>echo "<a href='" . htmlentities($_SERVER['PHP_SELF']) . "?keywords=" . urlencode($keywords) . "&limit=" . urlencode($limit) . "&page=" . urlencode($total_pages) . "'>FINAL PAGE</a> ";
printf()
$full_name_concat = $first_name . " " . $last_name;
//output: Jeff Everhart
$full_name_interpolate = "{$first_name} {$last_name}";
//output: Jeff Everhart
$full_name_interpolate_v2 = "$first_name $last_name";
$full_name_interpolate_v2 = "$first_name $last_name";
$full_name_concat = "$first_name" ." " ."$last_name";
//output: Jeff Everhart
$full_name_concat = $first_name ." " .$last_name;
//output: Jeff Everhart
$full_name_interpolate = "{$first_name} {$last_name}";
$self_page = htmlentities($_SERVER['PHP_SELF']);
$keywords=urlencode($keywords);
if($page>$total_pages) //Display Link to Final Page only.
{
echo "<a href="$self_page?keywords=$keywords&limit=$limit&page=$total_pages">FINAL PAGE</a>";
}
else
{
$i=1;
while($i<=$total_pages)//Display the Pagination Section.
{
if($i==$page) //Bold the 'current page' Link.
{
echo "<a href="$self_page?keywords=$keywords&limit=$limit&page=$i"><b>$i</b></a>";
}
else
{
echo "<a href="$self_page?keywords=$keywords&limit=$limit&page=$i">$i</a>";
}
$i++;
}
}
echo "<a href='" . htmlentities($_SERVER['PHP_SELF']) . '?keywords=' . urlencode($keywords) . '&limit=' . urlencode($limit) . '&page=' . urlencode($total_pages) . "'>FINAL PAGE</a> ";
echo "<a href='htmlentities($_SERVER['PHP_SELF']). '?keywords=' .urlencode($keywords) . '&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) .'>FINAL PAGE</a>' ";
echo "<a href='" . htmlentities($_SERVER['PHP_SELF']) . "?keywords=" . urlencode($keywords) . "&limit=" . urlencode($limit) . "&page=" . urlencode($total_pages) . "'>FINAL PAGE</a> ";
echo "<a href='" .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) ."'>FINAL PAGE</a>";
echo '<a href=' ' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) .''>FINAL PAGE</a>';
if($page>$total_pages) //Display Link to Final Page only.
{
echo "<a href='" .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) ."'>FINAL PAGE</a>";
}
else
{
$i=1;
while($i<=$total_pages)//Display the Pagination Section.
{
if($i==$page) //Bold the 'current page' Link.
{
echo "<a href='" .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($i) ."'><b>$i</b></a>";
}
else
{
echo "<a href='" .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($i) ."'>$i</a>";
}
$i++;
}
}
if($page>$total_pages) //Display Link to Final Page only.
{
echo '<a href=' ' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) .''>FINAL PAGE</a>';
}
else
{
$i=1;
while($i<=$total_pages)//Display the Pagination Section.
{
if($i==$page) //Bold the 'current page' Link.
{
echo '<a href=' ' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($i) .''><b>$i</b></a>';
}
else
{
echo '<a href=' ' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($i) .''>$i</a>';
}
$i++;
}
}
if($page>$total_pages) //Display Link to Final Page only.
{
echo '<a href='' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) ."'>FINAL PAGE</a>";
}
else
{
$i=1;
while($i<=$total_pages)//Display the Pagination Section.
{
if($i==$page) //Bold the 'current page' Link.
{
echo '<a href='' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($i) ."'><b>$i</b></a>";
}
else
{
echo '<a href='' .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($i) ."'>$i</a>";
}
$i++;
}
}
printf("<a href="%s?keywords=%s&limit=%d&page=%d">FINAL PAGE</a>",htmlentities($_SERVER['PHP_SELF']),urlencode($keywords),$limit,$total_pages);
echo "<a href='" .htmlentities($_SERVER['PHP_SELF']) .'?keywords=' .urlencode($keywords) .'&limit=' .urlencode($limit) .'&page=' .urlencode($total_pages) ."'>FINAL PAGE</a>";
printf("<a href="%s?keywords=%s&limit=%d&page=%d"><b>Final Page</b></a>",htmlentities($_SERVER['PHP_SELF']),urlencode($keywords),urlencode($limit),urlencode($total_pages));
printf("<a href='%s?keywords=%s&limit=%d&page=%d'><b>Final Page</b></a>",htmlentities($_SERVER['PHP_SELF']),urlencode($keywords),urlencode($limit),urlencode($total_pages));
>@developer_web#1622908 NachFolger secured also the $limit & $page with echo. I asked him to show me how to do it with echo over printf.
0.1.9 — BETA 5.26