Solved: Php Within Variable text.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

skibum35

Thread Starter
Joined
Aug 16, 2005
Messages
71
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

Code:
$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.

Thanks.
 
Joined
Apr 6, 2008
Messages
101
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
so
$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
 

skibum35

Thread Starter
Joined
Aug 16, 2005
Messages
71
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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top