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.
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>";
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.