[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] det her må kunne gøres pænere



Anders Ossowicki wrote:
> Følgende kodestump må kunne omskrives til noget mere elegant. Formålet er
> vist åbenlyst (at konvertere [url]-tags til links), men problemet er, at for
> at overholde xhtml-standarden skal & skrives i html-notationen, &
> 
> $input = str_replace("&", "&amp;", preg_replace("{\[url\](.*?)\[/url\]}", "<a href='\\1'>\\1</a>",$input));
> $input = str_replace("&", "&amp;", preg_replace("{\[url=(.*?)\](.*?)\[/url\]}", "<a href='\\1' title='\\1'>\\2</a>",$input));
> /* Ugly as hell, but this should make &amp; in the textual representation go away */
> $input = preg_replace("{(<a.*>.*)&amp;(.*</a>)}", "\\1&\\2", $input);

Jeg har netop svaret paa et lignende spoergsmaal andetsteds. Du kan bare
konvertere alle forekomster af & der ikke er efterfulgt af amp; - de
skal jo alligevel erstattes:

<?php
  $input = preg_replace('/&(?!amp;)/', '&amp;', $input);
?>

-- 
Christian Joergensen | Linux, programming or web consultancy
http://www.razor.dk  |     Visit us at: http://www.gmta.info



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-07-01, 02:01 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] *