I got from a json feed this :
<img src = "http://produits-lemieux.com/produits/bainmoussant_hg.jpg" ></img>
i need to inject alt=""
into the string
Best method to do that in php ?
I got from a json feed this :
<img src = "http://produits-lemieux.com/produits/bainmoussant_hg.jpg" ></img>
i need to inject alt=""
into the string
Best method to do that in php ?
string = '<img src = "http://produits-lemieux.com/produits/bainmoussant_hg.jpg" ></img>';
str_replace('></img>', 'alt=""></img>', $string);
Not sure why you have </img>
when you can just do: alt="" />
Manipulate the HTML DOM with the DOM functions ?
$doc = new DOMDocument();
$doc->loadHTML("<html><body>Test<br></body></html>");
$params = $doc->getElementsByTagName('img'); // Find Sections
foreach($params as $param)
{
$attribute = $doc->createAttribute('alt');
$param->appendChild($root_attr1);
$attributeText = $doc->createTextNode('This is the ALT attribute');
$attribute->appendChild($root_text);
}
$doc->saveHTML();
You can add an attribute with the createAttribute function.