insert php code into a variable

i am using a cms -oscommerce 234, with bootstrap3 added.

i have a file bm_logo.php which i have div’d out like this

[php] $data = ‘

’ . tep_image(DIR_WS_IMAGES . ‘store_logo.png’, STORE_NAME) . ‘
’.
  '<div class="col-md-6 col-md-pull-6">
    <a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . 'store_logo.png', STORE_NAME) . '</a></div>';[/php]

in the second div i want to remove the logo and replace it with php code from the header navigation.
generally with this code.

i have tried a number of solutions time to ask for help.

thanks

[php]

[/php]

Well, not sure what you are asking for. In the first code sample you show how to load up a PHP variable with
HTML code. In the second one you show how to set up HTML with PHP data inserted into the HTML code.

You asked to replace the image in the first code with the entire second code. So, this is not really clear on
what you want to do.

Do you mean that you want to place the entire second section of code where you have the image in the
first section? Can’t do that because the image in the first section is inside an anchor. If you mean you want
to replace that entire anchor on line #5 of the first section, you can do that easily, but, you have to make
sure that your quotes are handled correctly. Nested quotes is usually why this fails. In both of your
samples of code, you use both single and double quotes. When you add in HTML into PHP code variables,
you just have to make sure that the quotes are correct. Therefore, setting up your $data variable, you can
do something like:
$data = ‘

<?PHP echo "some php outputs"; ?>
’;
This is valid because you are using one OUTSIDE single quotes and a matched pair of double INSIDE quotes.
In combining your second section of code into the first code section, which can be done, you must be very
careful on the use of single and double quotes. You can not use the OUTSIDE quote as an INSIDE quote.
Therefore, this will not work:
$data = ‘
<?PHP echo 'some php outpus'; ?>
’;
As you can see this is invalid as it pulls the data out as: = '
<?php echo '; and the rest gets messed
up. SO, I think it is most likely just a formatting issues.

Try to combine them being very careful on the quote usage and let us know your results. Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service