Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add PHP-Code to an attribute using DOM on PHP?

How can I do somethink like this with PHP DOM?

<img src="<?php echo $picsrc; ?>">

This Code

$node->setAttribute('src','<?php echo $picsrc;?>');

does escape the PHP Tag.

<img src="&lt;?php echo $picsrc; ?&gt;">

Is there a way to use

$dom->createProcessingInstruction()

for Attribute Values?

like image 912
Robin Fleischer Avatar asked Mar 05 '26 02:03

Robin Fleischer


1 Answers

You should try this

$srcPath = '<?php echo $picsrc;?>';
$node->setAttribute('src', html_entity_decode($srcPath));
like image 115
Vitalii Zurian Avatar answered Mar 07 '26 16:03

Vitalii Zurian