/** * Our own little parser as there doesn't seem to be a reasonable one that works * with both PHP4 and PHP5. A bit cumbersome and certainly not nice but it seems * to work. * * @param string $content * @return string */ function getInlineDescription($content, $className = 'photoQDescr') { $descr = ''; $photoQDescrTagsInnerHTML = array(); $pTags = PhotoQHelper::getHTMLTags('div', $content); PhotoQHelper::debug('pTags: ' . print_r($pTags, true)); foreach ($pTags as $pTag) { $matches = array(); $found = preg_match('#^(<div.*?class="' . $className . '".*?>)#', $pTag, $matches); if ($found) { //remove the p start and end tag, the rest is the description. array_push($photoQDescrTagsInnerHTML, str_replace($matches[1], '', substr($pTag, 0, strlen($pTag) - 6))); } } PhotoQHelper::debug('photoQDescrTagsInnerHTML: ' . print_r($photoQDescrTagsInnerHTML, true)); //if we have more than one p.photoQDescr tag, it means that there were several //lines created in the editor -> wrap each one with a p tag. $numDescrTags = count($photoQDescrTagsInnerHTML); if ($numDescrTags == 1) { $descr = $photoQDescrTagsInnerHTML[0]; } else { for ($i = 0; $i < $numDescrTags; $i++) { if ($photoQDescrTagsInnerHTML[$i] !== '') { $descr .= "<p>{$photoQDescrTagsInnerHTML[$i]}</p>"; } } } PhotoQHelper::debug('descr:' . $descr); return $descr; }