Mailinglisten-Archive |
Hallo zusammen,
gerade brüte ich auch über einem Pattern, das aber so nicht wirklich
funktioniert, wie ich es bräuchte...
Das Problem:
Ich habe (HTML-) Texte, in denen bei Vorkommen eines Musters noch ein
Tag eingebaut werden soll. Die Texte sind mehrzeilig - zum Beispiel so
was hier:
-------------------------<schnipp-schnapp>-------------------------
<p><div class="picture_left"><img src="/imglib/742ec334" alt="" title=""
width="250" height="120" border="0"><br />Saski Crescent,
Warsaw</div>Our full
range of design and construction services include urban planning, concept
design, building architecture, landscaping and interior space planning. By
collaborating with renowned local and international architects and
construction
companies we aim to optimise each property by achieving a harmony with its
location and future use. </p>
<p>For each
project we assemble an experienced, top-notch multidisciplinary
architectural
design and construction team of professionals, managed and coordinated
by our
in-house construction team. </p>";
-------------------------<schnipp-schnapp>-------------------------
So, sofern nun innerhalb eines Absatzes (<p> ... </p>) das Tag <div
class="picture_left"> vorkommt, dann soll direkt nach dem ersten
"</div>" das Tag <div align="justify"> und passend direkt vor dem ersten
"</p>" noch ein </div> eingebaut werden.
Im Prinzip funktioniert das mit folgender Methode:
-------------------------<schnipp-schnapp>-------------------------
if (stristr($text, 'class="picture_left"'))
{
$pattern="/<div class=\"picture_left\">.*<\/div>([\s|\S]*?)(<\/p>){1}/i";
preg_match($pattern,$text,$matches);
$pat=$matches[1];
$text=preg_replace("/".$pat."/i","<div
align=\"justify\">$pat</div>",$text);
}
-------------------------<schnipp-schnapp>-------------------------
Man sieht wohl schon, dass ich darin nicht sehr geübt bin, das ganze
geht garantiert auch viel kürzer, aber mir ist momentan nur das Ergebnis
wichtig, und daran hapert es, weil nämlich innerhalb von $matches[1]
auch noch Slashes (/) und/oder HTML-Tags vorkommen können, die das
preg_replace komplett aus dem Takt bringen...
Ich weiß, dass das viel Zeugs ist, aber vielleicht hat ja der eine oder
andere die Muse oder Standardwissen, das Problem zu lösen zu helfen....
Grüße,
Roman.
php::bar PHP Wiki - Listenarchive