简体   繁体   中英

PHP inside echo in a function?

I have this part of the code of a plugin, which continues and has much php before it, fluidly without the ?> till the end of all the code.

function fivu_thumbnail_meta_box_html() {
echo '<label for="featured_image_url">';
_e("URL of featured image", 'fivu_textdomain' );
echo '</label> ';
echo '<input type="text" id="featured_image_url" name="featured_image_url" value=""    size="30" />'; 
}

What i need is to change the input value="" (5th line) to this:

value="<?php get_post_custom_values("Poster"); ?>" 

But as i am inside of an echo, the php is not interpreted as php but as normal text. ¿What can i do to make the php inside of the echo not to be interpeted as normal text?

EDIT: Ok, i am using

echo '<input type="text" id="featured_image_url" name="featured_image_url" value="' .    get_post_custom_values("Poster") . '"    size="30" />'; 

But i forgot, lol, i need to echo the value. So how do i add: echo $values[0]; ?

You don't need <?php again as you're already inside a PHP control. You simply need to concatenate your string with the get_post_custom_values function's return value, like so:

echo '<input ... value="'.get_post_custom_values("Poster").'" ... />'; 

So we have string + function's return value + string, three components which together contribute to the output of the input field HTML.

I don't like HTML in echo.

So Try :-

function fivu_thumbnail_meta_box_html() {
?>
<label for="featured_image_url">
<?php
_e("URL of featured image", 'fivu_textdomain' );
?>
</label>
<input type="text" id="featured_image_url" name="featured_image_url" value="<?php echo get_post_custom_values("Poster"); ?>"  size="30" />
<?php 
}

Use the string concatenation operator , . :

echo '<input type="text" id="featured_image_url" name="featured_image_url" value="' . get_post_custom_values("Poster") . '"    size="30" />'; 

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