I have a text that contains html tags, such as:
$html = '<td width="71%" valign="top"><img src="https://path/mobilPay.jpg" alt="" width="100%" border="0" style="display:block" /></td><td width="15%"><img src="https://path/mobilPay2.jpg" alt="" width="100%" border="0" style="display:block" /><img src="https://path/mobilPay.jpg" alt="" width="100%" border="0" style="display:block"/></td>';
preg_match_all('/<img[^>]+>/i',$html, $imgTags);
for ($i = 0; $i < count($imgTags[0]); $i++) {
// get the source string
preg_match('/src="([^"]+)/i',$imgTags[0][$i], $imgage);
// remove opening 'src=' tag, can`t get the regex right
$origImageSrc[] = str_ireplace( 'src="', '', $imgage[0]);
}
//echo '<pre>';
print_r($origImageSrc);
//echo '</pre>';
In $origImageSrc are returned all the src from all tags.
I want to replace the tag containing a src with a specific text (for all src=”https://path/mobilPay.jpg” I need TEXT1, for src=”https://path/mobilPay2.jpg” i need TEXT2).
For example, I want to display something like:
<td width="71%" valign="top">TEXT1</td><td width="15%">TEXT2 TEXT1</td>
In $imgTags are returned the tags, but not with the proper termination ( > instead of />, or it can be a space before /> ), therefore I cannot use that array.
Please help! How can I replace the whole tag with a specific text ?