开发者

Is this possible to use a variable for an url in php?

开发者 https://www.devze.com 2023-02-12 05:57 出处:网络
I\'m calling a function like this: <?php print get_thumbnail(\'http://url.com/?skin=rss\'); ?> Being a php newbie, I\'m wondering if there is a way to change the http://url.com part based on a

I'm calling a function like this:

<?php print get_thumbnail('http://url.com/?skin=rss'); ?>

Being a php newbie, I'm wondering if there is a way to change the http://url.com part based on a custom metadata I have set up in Wordpress. So I gues开发者_运维百科s it would look something like this:

<?php print get_thumbnail('<?=$video_src?>/?skin=rss'); ?>

Is something like this possible?


Yes, you have the right idea, you just don't need to re-open PHP tags since you're already inside some. You can use . to concatenate (join together) the value of $video_src and "?skin=rss".

<?php print get_thumbnail($video_src . "?skin=rss"); ?>


Try this:

<?php print get_thumbnail($video_src . '/?skin=rss'); ?>

Keep in mind that <?= $foo ?> is shorthand for <?php echo $foo; ?>. <?= ?> won't be expanded in strings, but you can achieve something similar using double quoted strings:

<?php print get_thumbnail("$video_src/?skin=rss"); ?>


Yes, except within PHP, you don't need to enter the PHP tags again.

<?php print get_thumbnail($video_src . '/?skin=rss'); ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号