emsy Posted March 28, 2010 Report Share Posted March 28, 2010 (edited) Sveiki. Man ir tāda problēma, man ir vajadzīgs, lai code bb kodu tagos var ievadīt tekstu vairākās rindās: šobrīd mans BBkods izskatās šādi: function bbc($value) { $bb_replace = array( '/(\[code])(.+)(\[\/code\])/' ); $bb_replacements = array( "<div class='code-field'>\\2</div>" ); $value = preg_replace($bb_replace, $bb_replacements, $value); return $value; } Man vajag panākt, lai nebūtu tā: ['code] kods kods kods ... [/code] Pieņemsim, ka tās pēdiņas tur nav (['code]) Bet būtu tā: kods kods kods ... Edited March 28, 2010 by emsy Quote Link to comment Share on other sites More sharing options...
xcwcx Posted March 28, 2010 Report Share Posted March 28, 2010 (edited) '/(\[code])(.+)(\[\/code\])/m' http://php.net/manual/en/reference.pcre.pattern.modifiers.php Edited March 28, 2010 by xcwcx Quote Link to comment Share on other sites More sharing options...
emsy Posted March 28, 2010 Author Report Share Posted March 28, 2010 '/(\[code])(.+)(\[\/code\])/m' http://php.net/manual/en/reference.pcre.pattern.modifiers.php Arī šādi nestrādā :(, paskatījos linku, papētīju paeksperimentēju, bet nekas nesanāca. Quote Link to comment Share on other sites More sharing options...
2easy Posted March 28, 2010 Report Share Posted March 28, 2010 (edited) '/(\[code])([\s\S]+)(\[\/code\])/' Edited March 28, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
emsy Posted March 29, 2010 Author Report Share Posted March 29, 2010 '/(\[code])([\s\S]+)(\[\/code\])/' Aizgāja, paldies :) Quote Link to comment Share on other sites More sharing options...
2easy Posted March 29, 2010 Report Share Posted March 29, 2010 es pagaidīju, lai tu pasaki, ka ir ok, lai tev pateiktu, ka nav ok :D:D:D jo ja tu izmantosi [\s\S]+ tas paņems visus code uzreiz (ja būs vairāki [ code] tagi) tāpēc lai tas būtu pieticīgāks un apstrādātu katru [ code]...[/code] atsevišķi, galā vajag pielikt ? kr4 šādi [\s\S]+? (dažās vietās ieliku atstarpes, lai teksta/piemēra code nejuktu kopā ar foruma posta formatēšanu) function bbc($s) {return preg_replace('/\[code]([\s\S]+?)\[\/code]/', '<div class="code-field">\\1</div>', $s);} $s = '[code] aaa bbb [/code ] [code] 111 222 [/code ]'; echo bbc($s); pamēģini pats paexperimentēt ar/bez ? un tik vnkāršas funkcijas raksta vienā rindiņā ;) Quote Link to comment Share on other sites More sharing options...
emsy Posted March 29, 2010 Author Report Share Posted March 29, 2010 un tik vnkāršas funkcijas raksta vienā rindiņā ;) Tas nebija viss kods, es parādīju tikai fragmentu no tā visa ;), tbš tur bija kkādi 20 BBkodi Quote Link to comment Share on other sites More sharing options...
marcis Posted March 29, 2010 Report Share Posted March 29, 2010 php.net/bbcode Quote Link to comment Share on other sites More sharing options...
2easy Posted March 29, 2010 Report Share Posted March 29, 2010 daļēji jau tev ir taisnība, ka mēs te atkal riteni izgudrojam, taču norepleisot dažus tagus jau nav nekas trax :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.