1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Php Within Variable text.

Discussion in 'Web Design & Development' started by skibum35, Apr 10, 2008.

Thread Status:
Not open for further replies.
  1. skibum35

    skibum35 Thread Starter

    Aug 16, 2005
    Hows that for a confusing title.

    What I am trying to do is echo a variable within some text that is within a variable.

    Even more confused? Me too.

    I want to set up some adsense boxes on a page.

    Will echo a variable on the page. This is the start of the code for the variable

    $top_adsense = "
      <script type='text/javascript'><!--
      google_ad_client = '<?php echo $adsense_publisher_id; ?>';
      google_ad_width = 728;
    Of course it is rendering all that literally.

    I have tried some work arounds to no avail.

    The eyes are square at the moment, have looked up what I thought was the relevent area in books, but cannot find the answer. Thought I would ask you folks here.

    Can this be done?

    I know I can work around this by just using files without being within php variables, but there has to be a way.

  2. Mudley


    Apr 6, 2008
    If you're trying to set all the code as a variable, do so with a period

    like $var = 'Your strings or <b>html code</b> and then some variable ' . $output . ' and then some more <i>html</i>';

    you can also break in and out of php as long as the code is exactly where it needs to be output
    <script type='text/javascript'><!--
    google_ad_client = '<?=$adsense_publisher_id; ?>
    google_ad_width = 728;
    --> </script>

    allllso, here's some knowledge of php and strings and vars
    double quotes will parse variables with their values
    $var = 'hi mom';
    echo "$var"; // output would be: hi mom
    echo '$var'; // output would be: $var (as a string)
    echo 'Value of $var is ' . $var; // output would be: Value of $var is hi mom
  3. skibum35

    skibum35 Thread Starter

    Aug 16, 2005
    Thanks heaps Mudley.

    Used the period way and is working spot on.

    I don't know why I forgot that one.
    Been too long in front of this computer. Brain starting to fry.

    Thanks again
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Similar Threads - Solved Within Variable
  1. Damonc
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/702286

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice