[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 wrote:
Hans Schou wrote:

On Sat, 2 Jul 2005, Anders Ossowicki wrote:


Jeg har et stykke tekst i en variabel ($body). Denne tekst kan evt. indeholde [b], [/b] tags (tilsvarende for [i], [u] og [url]).
Jeg ønsker at løbe den tekst igennem, og finde de forekomster hvor der både er et start _og_ slut-tag for derefter at erstatte dem med relevante html-tags.



Jeg er klar over at strpos og str_replace er noget af det jeg skal



Jeg tror preg_replace er stærkere til at håndterer dette.


Noget ala:
"\[i\](.*)\[/i\]"  "<i>\\1</i>"

Den kode returnerer: Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in Når den bliver sat ind i preg_replace: $body = preg_replace("\[i\](.*)\[/i\]","<i>\\1</i>",$body); Selv har jeg endnu ikke helt styr på preg_replace, så hvad er der galt der?
Okay, har læst lidt op på regexp og det lader til at der skal være delimiters, der afgrænser søgeteksten. Følgende kode virker:
$body = preg_replace("{\[i\](.*)\[/i\]}","<i>\\1</i>",$body);


Tak for hjælpen!
---
Anders


 
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] *