Home > Net >  How to use a <?php echo urlencode($term);?> tag inside a php script
How to use a <?php echo urlencode($term);?> tag inside a php script

Time:11-26

I am trying to include a tag that works well all over the webpage but I need to figure out how to make it function inside a existing php script that is in the same page. Below is the example I am looking to make work. This way the rss feed will track the keywords that was 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);

?>

CodePudding user response:

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) ?>

CodePudding user response:

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

?>
  •  Tags:  
  • php
  • Related