Hello,
I am trying to implement the following code but am finding that it does not work for some reason. It converts any <img> tags to XHTML 1.0 compliant format and adds an alt tag with a predefined value. I hope someone can point me in the correct part to modify/correct/replace please. $source contains the html code being fed to it.
Thanks,Code:Function convertToXHTML_img($source) { // Since <img> has not closing tag, remove all $newDescription = str_replace("</img>", "", "$source"); // Use regular expressions to find <img ... > if (preg_match_all("/<img[^>]*>/i", $newDescription, $match) !== FALSE) { // Make sure it truely was a match for ($x = 0; $x < count($match[0]); $x++) { if ($match[0][$x] != "") { // Save the image $theImage = $match[0][$x]; // If the tag isn't closed with />, make it so if (stristr(str_replace(" ", "", $theImage), "/>") === FALSE) { $theImage = str_replace(">", "/>", $theImage); } // Check for the alt="" tag if (stristr(str_replace(" ", "", $theImage), "alt=") === FALSE) { $theImage = str_replace("/>", " alt=\"$xyz\" />", $theImage); } // Remove the image from the description $newDescription = str_replace($match[0][$x], $theImage, $newDescription); } } } return $newDescription;
Claudek







Bookmarks