-2

I have what most likely is a very simple question for you experienced PHP developers out there, I am trying to add some PHP code to a PDF generation software that I am currently using.

The issue that I am having I believe lies in my quotes. I have tried single quotes, double quotes with a single quote on the outside, escaping the php, just about everything that I could think of, still no luck.

My code currently looks like this:

<?php 
// add code to check if data
if (!empty($form_data['field'][39]))
{

echo "<div style="text-align:center;">
<?php foreach($form_data['field'][274] as $url):?> <img src="<?php echo str_replace(site_url(), ABSPATH, $url); ?>" width="250px" /> <?php endforeach; ?  >
 </div>";
?>

What I am trying to accomplish is this, when there is data entered into 'field' 39, it should echo the generated image below. This image though is generated dynamically, so I need to replace the URL as such so I have the str replace for the site url, but I am unsure of which quotes to change throughout this echo, all my attempts have just broken the PDF that is generated.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • 3
    Missing `";` after `echo "
    `, and you should either switch to single-quotes on the outer ones there, or escape the double ones inside: `echo "
    ";` - and the `"; ?>` at the end are redundant, you're not in PHP there. (But you have a space between `? >` after the `endforeach;`)
    – Qirel Mar 31 '16 at 18:16
  • 1
    also where is your if condition is closed? – Alive to die - Anant Mar 31 '16 at 18:18
  • Also why you generate html code with php? You should prepare your output divs beforehand and then use the js or post the html code outside of php. –  Mar 31 '16 at 18:20

1 Answers1

1

I can't be certain that this is correct in your context, but this is at least syntactically correct. Try it.

<?php
// add code to check if data
    if (!empty($form_data['field'][39]))
    {

        echo "<div style='text-align:center;'>";
            foreach($form_data['field'][274] as $url):
         ?>
            <img src="<?php echo str_replace(site_url(), ABSPATH, $url); ?>" width="250px" />
         <?php
            endforeach;
        echo "</div>";
    }
?>
bassxzero
  • 4,838
  • 22
  • 34