开发者

Invisible spaces in PHP function result

I'm working on making one of my first wordpress themes, but I seem to be encountering a weird issue. Whenever I call one of my functions with PHP, the return (when viewing the page) has a lot of wh开发者_StackOverflow社区ite space (invisible characters). For some of the things I'm trying to do, it causes problems. Here's an example of one of my functions, the rest are built just like it.

 // Get YouTube Username
 function soc_youtube() {
 global $up_options;
 ?>

 <?php if($up_options->soc_youtube){ ?>
  <?php echo $up_options->soc_youtube; ?>
  <?php
  }
 }

That code generated this result:

Invisible spaces in PHP function result

Update: Fixed

Solution: Use less tags and cut down on breaks in code


Everything outside the php tags is pushed through directly to the output, including all your line breaks. To avoid that, leave the line breaks inside the PHP code:

 <?php if($up_options->soc_youtube){
 ?><?php
   echo $up_options->soc_youtube;
 ?><?php   //...

(In your example, I don't see the need to close any of the tags at all, though. You could just have everything inside one set of tags.)


First, there is no need to end a php block and start it right back up again with nothing in between... especially on every single line. Try getting rid of those first and see if that makes a difference:

// Get YouTube Username
function soc_youtube() {
    global $up_options;
    if($up_options->soc_youtube){ 
        echo $up_options->soc_youtube;
    }
}

Next, if that doesn't work, try doing var_dump($up_options->soc_youtube); and see what's there and figure out why.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜