-1

I am trying to include a <?php echo urlencode($term);?> tag that works well across every page on my website, but I need to figure out how to make it function inside an existing PHP script that is in the same page.

Below is the example that I am trying to fix. This way the RSS feed will track the keywords that were used in the search automatically.

<?php
// output RSS feed to HTML
output_rss_feed('https://www.speedyfind.net/search/feed.php?Terms=<?php echo urlencode($term);?>', 6, true, true, 200);
?>
karel
  • 5,489
  • 46
  • 45
  • 50

2 Answers2

1

Your attempt is correct, however you are unnecessarily invoking the <?php tag whilst already within one, this is causing the operation to fail.

The correct way to concatenate your urlencode() call is to use the . operator.

output_rss_feed('https://www.speedyfind.net/search/feed.php?Terms=' . urlencode($term) . '', 6, true, true, 200);

A side note for future reference, when you are performing one inline operation, you can use the short open tag that echos the result of the operation back to the page.

<?php
echo urlencode($term);
?>

is the same as:

<?= urlencode($term) ?>
Skully
  • 2,882
  • 3
  • 20
  • 31
0

You don't need to use <?php tags again to access the $term variable inside php tag. You can access it something like this:

<?php

// output RSS feed to HTML

output_rss_feed("https://www.speedyfind.net/search/feed.php?Terms='. urlencode($term) . '", 6, true, true, 200);

?>
mk23
  • 1,257
  • 1
  • 12
  • 25