[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
 

[PHP] preg_replace (regexp) er forkert



Oy!

Følgende php-funktion bør udskifte en række bb-code tags med html. Det fungerer også fint med undtagelse af sektionen med smileys. Problemet er, at hvis jeg fjerner de mellemrum der er mellem de to / i de forskellige udtryk så får det også indvirkning på URL-adresser. Men løsningen med mellemrum er heller ikke optimal, da de kræver et mellemrum på begge sider af smileyen. Hvis jeg fjerner det bagerste mellemrum i udtrykkene fungerer de to udtryk :lol: og :idea: ikke.
Er der nogle kvikke hoveder der kan gennemskue hvordan den bedst kringles? En mulighed var at undgå at tjekke for smilies på url-adresser (men hvordan?)


//Anders

function tag_replace($input) {
$input = preg_replace("{\[i\](.*?)\[/i\]}","<i>\\1</i>",$input);
$input = preg_replace("{\[b\](.*?)\[/b\]}","<b>\\1</b>",$input);
$input = preg_replace("{\[u\](.*?)\[/u\]}","<u>\\1</u>",$input);
$input = preg_replace("{\[url\](.*?)\[/url\]}","<a href='\\1' target='_blank'>\\1</a>",$input);
$smilies = array(
"/ \:\) /" => "forum/smiles/icon_smile.gif",
"/ \:\-\) /" => "forum/smiles/icon_smile.gif",
"/ \:\( /" => "forum/smiles/icon_sad.gif",
"/ \:\-\( /" => "forum/smiles/icon_sad.gif",
"/ >\:\( /" => "forum/smiles/icon_frown.gif",
"/ >\:\-\( /" => "forum/smiles/icon_frown.gif",
"/ \:\'\( /" => "forum/smiles/icon_cry.gif",
"/ \:\'\-\( /" => "forum/smiles/icon_cry.gif",
"/ \;\) /" => "forum/smiles/icon_wink.gif",
"/ \;\-\) /" => "forum/smiles/icon_wink.gif",
"/ \:\S /" => "forum/smiles/icon_confused.gif",
"/ \:\-\S /" => "forum/smiles/icon_confused.gif",
"/ \:\D /" => "forum/smiles/icon_biggrin.gif",
"/ \:\-\D /" => "forum/smiles/icon_biggrin.gif",
"/ \o\.\O /" => "forum/smiles/icon_eek.gif",
"/ \O\.\o /" => "forum/smiles/icon_eek.gif",
"/ \o\.0 /" => "forum/smiles/icon_eek.gif",
"/ 0\.\o /" => "forum/smiles/icon_eek.gif",
"/ >\:\) /" => "forum/smiles/icon_twisted.gif",
"/ >\:\-\) /" => "forum/smiles/icon_twisted.gif",
"/ \(6\) /" => "forum/smiles/icon_evil.gif",
"/ \(\!\) /" => "forum/smiles/icon_exclaim.gif",
"/ \(\?\) /" => "forum/smiles/icon_question.gif",
"/ \(\->\) /" => "forum/smiles/icon_arrow.gif",
"/ \:p /" => "forum/smiles/icon_razz.gif",
"/ \:\-p /" => "forum/smiles/icon_razz.gif",
"/ \:P /" => "forum/smiles/icon_razz.gif",
"/ \:\-P /" => "forum/smiles/icon_razz.gif",
"/ \:lol\: /" => "forum/smiles/icon_lol.gif",
"/ \:o /" => "forum/smiles/icon_surprised.gif",
"/ \:\-o /" => "forum/smiles/icon_surprised.gif",
"/ \:\| /" => "forum/smiles/icon_neutral.gif",
"/ \:\-\| /" => "forum/smiles/icon_neutral.gif",
"/ \:x /" => "forum/smiles/icon_mad.gif",
"/ \:\-x /" => "forum/smiles/icon_mad.gif",
"/ XD /" => "forum/smiles/icon_mrgreen.gif",
"/ X\-D /" => "forum/smiles/icon_mrgreen.gif",
"/ 8\) /" => "forum/smiles/icon_cool.gif",
"/ 8\-\) /" => "forum/smiles/icon_cool.gif",
"/ \:$ /" => "forum/smiles/icon_redface.gif",
"/ \:\-$ /" => "forum/smiles/icon_redface.gif",
"/ 8\| /" => "forum/smiles/icon_rolleyes.gif",
"/ 8\-\| /" => "forum/smiles/icon_rolleyes.gif",
"/ \:idea\: /" => "forum/smiles/icon_idea.gif",
);
foreach($smilies as $key => $value){
$input = preg_replace($key," <img border='0' src='$value'> ",$input);
}
return $input;
}


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

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