简体   繁体   中英

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

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

?>

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

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

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM