简体   繁体   English

PHP echo 引用语法错误

[英]PHP echo quote syntax error

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.对于您那里有经验的PHP开发人员,我最有可能是一个非常简单的问题,我正在尝试将一些PHP代码添加到我目前正在使用的PDF生成软件中。

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.我已经尝试过单引号,双引号和外面的单引号,逃避php ,几乎所有我能想到的,仍然没有运气。

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.我想要完成的是,当有数据输入到“字段”39 时,它应该与下面生成的图像相呼应。 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.该图像虽然是动态生成的,因此我需要替换 URL,因此我将 str 替换为站点 url,但我不确定在整个回声中要更改哪些引号,我所有的尝试都只是破坏了 PDF生成。

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>";
    }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM