[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [PHP] Gennegå tekst og tilpasse tags



Anders Ossowicki <sslug@sslug> writes:

>>>Noget ala:
>>>"\[i\](.*)\[/i\]"  "<i>\\1</i>"
>> [i]Det[/i] tror jeg ikke er den mest [i]optimale[/i] måde at løse
>> [i]den[/i] opgave på. (-- i hvert fald ikke hvis php regexp opfører
>> sig som alle mulige andre)
>>
> Hvad ville du så anbefale?

Jeg ser to lette regexp løsninger. Den Hans foreslår som vil bevirke
at mit svar bliver til:

  <i>Det[/i] tror jeg ikke er den mest <i>optimale</i> måde at løse
  [i]den</i> opgave på.

Alternativet er en løsning der anvender ikke-grådige matches, det vil
sige "\[i\](.*?)\[/i\]" istedet. Ved nestede tags vil den godt nok
udskifte slut-taggene i en forkert rækkefølge, men nok give det
korrekte slutresultat.

Der er også et spørgsmål med at definerer hvad du vil gøre med tags
der ikke balancerer:

  [i]Det er en [i]god[/i] ide.

  [i]Det[/i] er en god[/i] ide.

Specielt hvis du efterfølgende vil fjerne ikke-matchende tags fra
teksten kan det blive relevant.

Alt efter hvordan du vil have det kan strpos og substr_replace give en
bedre løsning. Find offsets med strpos og eventuelt strrpos og erstat
enkelt-tags med substr_replace.

Hvis du bruger PHP4 skal du selv implementere en strrpos med strrev og
strpos. (hvis jeg læser dokumentationen rigtigt)

-- 
 Peter Makholm     |        One thing you do is prevent good software from
 sslug@sslug |      being written. Who can afford to do professional
 http://hacking.dk |                                     work for nothing?
                   |                                         -- Bill Gates


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *