简体   繁体   English

动态值 <img> dompdf中的src属性

[英]Dynamic value in <img>'s src attribute in dompdf

I am making a pdf of invoices for multiple companies. 我正在为多家公司制作pdf格式的发票。 Every company has their own logo which they want to be going on the pdf. 每个公司都有自己的徽标,希望在PDF上使用。 I am using dompdf for the sake of pdf generation. 我正在使用dompdf来生成pdf。 Now when hard code the value of src attribute with the relative path of the image it is rendered perfectly fine on the pdf. 现在,当对代码的src属性值和图像的相对路径进行硬编码时,可以在pdf上完美呈现它。 Eg in codeigniter: 例如在codeigniter中:

$this->load->helper(array('dompdf', 'file'));
$html = '<img style = "height: 140px; width: 180px;" src = "images/logo.png" />';
pdf_create($html, 'filename');
$data = pdf_create($html, '', false);

Now, as the image's relative path is going to change everytime depending on the client logged in I am trying to give src attribute a dynamic value like such: 现在,由于图像的相对路径每次都会更改,具体取决于登录的客户端,因此我尝试为src属性赋予一个动态值,例如:

$this->load->helper(array('dompdf', 'file'));
$html = '<img style = "height: 140px; width: 180px;" src = '; $row->img; $html.=' />';
pdf_create($html, 'filename');
$data = pdf_create($html, '', false);

Where $row->img has the value = images/logo.png for a certain case.(the value is going to change depending on who is logged in). 在特定情况下,$ row-> img的值为= images / logo.png(该值将根据登录的人而改变)。

Using the above code just gives me a blank space on the pdf, not even a broken image neither any error message. 使用上面的代码只会给我pdf上的空白,甚至没有损坏的图像,也没有任何错误消息。 Please help me as its already taken one good day of mine. 请帮助我,因为我已经度过了美好的一天。

Comments, suggestions, answers are highly appreciated Thanks again. 评论,建议,答案受到高度赞赏。再次感谢。

尝试这个:

$html = '<img style = "height: 140px; width: 180px;" src ="'.$row->img.'"/>';

正则表达式:删除<img which src attribute is empty< div><div id="text_translate"><p> 我想要一个正则表达式模式来删除 src 属性为空的图像,例如:</p><pre> $html = '&lt;img src="adasas.jpg" /&gt;&lt;br /&gt;asasas&lt;br /&gt;sdfsdf&lt;br /&gt;&lt;img title="asa" src="" /&gt;';</pre><p> 或者</p><pre>$html = '&lt;img src="adasas.jpg" /&gt;&lt;br /&gt;asasas&lt;br /&gt;sdfsdf&lt;br /&gt;&lt;a href="adafgag"&gt;&lt;img title="asa" src="" /&gt;&lt;/a&gt;';</pre><p> 如果此&lt;img存在于&lt;a&gt;标记之间,我还想删除所有( &lt;a和&lt;img )。</p><p> 我测试了下面的代码,但它删除了所有 $html</p><pre> echo preg_replace( '?(&lt;a([^&gt;]+)&gt;).&lt;img(?*?)src=""([^&gt;]+)&gt;(&lt;/a&gt;),,si'; '' , $html );</pre><p> 任何人都可以帮助我吗?</p><p> 提前致谢</p></div> - RegEx : remove <img which src attribute is empty

暂无
暂无

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

相关问题 正在获取img标签,它是src值 - fetching img tag, and it's src value 将域添加到<img> src 属性值,如果是相对路径 - Add domain to <img> src attribute value if a relative path 根据引用 URL 的查询字符串替换 img src 值 - Replace an img src value based on a referring URL's query string 使用src属性作为href将img标记包装在标记中 - Wrapping an img tag in an a tag with the src attribute as the href PHP-解析的src属性 <img> 字符串标记 - PHP - parsing src attribute of <img> tag in string 删除不包含src属性的html中的img - Remove img in html that non contain src attribute PHP正则表达式替换img src属性中的内容? - PHP regex replace content in img src attribute? PHP 变量作为 img src 属性的输入 - PHP variable as input for img src attribute 正则表达式:删除<img which src attribute is empty< div><div id="text_translate"><p> 我想要一个正则表达式模式来删除 src 属性为空的图像,例如:</p><pre> $html = '&lt;img src="adasas.jpg" /&gt;&lt;br /&gt;asasas&lt;br /&gt;sdfsdf&lt;br /&gt;&lt;img title="asa" src="" /&gt;';</pre><p> 或者</p><pre>$html = '&lt;img src="adasas.jpg" /&gt;&lt;br /&gt;asasas&lt;br /&gt;sdfsdf&lt;br /&gt;&lt;a href="adafgag"&gt;&lt;img title="asa" src="" /&gt;&lt;/a&gt;';</pre><p> 如果此&lt;img存在于&lt;a&gt;标记之间,我还想删除所有( &lt;a和&lt;img )。</p><p> 我测试了下面的代码,但它删除了所有 $html</p><pre> echo preg_replace( '?(&lt;a([^&gt;]+)&gt;).&lt;img(?*?)src=""([^&gt;]+)&gt;(&lt;/a&gt;),,si'; '' , $html );</pre><p> 任何人都可以帮助我吗?</p><p> 提前致谢</p></div> - RegEx : remove <img which src attribute is empty 的src属性 <img> 发送邮件时丢失 - src attribute of <img> is missing when sending mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM