sviesc Posted May 7, 2004 Report Share Posted May 7, 2004 (edited) ir f-cija <?php function phpHighlight($code){ $code = "<?php\n".$code."\n?>"; $code = stripslashes($code); $code = highlight_string($code, true); $code = explode('<br />', $code); $text = "<table style='padding:0px; border-spacing: 0px 0px;'>"; for($x=0;$x<sizeof($code);$x++) $text .= "<tr><td style='font-family:Verdana; font-size:10px; vertical-align:middle; background-color:#FFFFE1;'>". ($x+1)."</td><td>". $code[$x]."</td></tr>"; $text .= "</table>"; return $text; } ?> es vēlētos šo f-ciju savienot ar $teksts = str_replace("[kods]","phpHighlight(",$teksts); $teksts = str_replace("[/kods]",");",$teksts); tā lai teksts kur atrodas starp [kods] un [/kods] tiktu atelots ar phpHighlight() palīdzību vai ir kādas idejas mans variants nestrādā vai arī teksts kur atrodas starp [kods] un [/kods] tiktu peņemts par mainigo $code tas manuprat ari deretu :blink: Edited May 7, 2004 by sviesc Link to comment Share on other sites More sharing options...
Gacha Posted May 7, 2004 Report Share Posted May 7, 2004 Nu megini darit shita: $code_start = strPos($data, "[kods]"); $code_end = strPos($data, "[/kods]"); $code = substr($data, $code_start, ($code_end - $code_start)); $code = str_replace("[kods]", "", $code); echo phpHighlight($code); Link to comment Share on other sites More sharing options...
sviesc Posted May 7, 2004 Author Report Share Posted May 7, 2004 vienīgais ko man atgriež ir tas teksts sterp [kods] un [/kods] pārējais eksts tiek aprīts vai arī es ko lāgā neesmu sprats tipa lietoju šādu te variantu $data = "shgdhsgahjdgashjd hjdsfjh dshfk jdshfk [kods] print(); include(); [/kods] jsajdh kjsakjd"; $code_start = strPos($data, "[kods]"); $code_end = strPos($data, "[/kods]"); $code = substr($data, $code_start, ($code_end - $code_start)); $code = str_replace("[kods]", "", $code); echo phpHighlight($code); :blink: Link to comment Share on other sites More sharing options...
Gacha Posted May 7, 2004 Report Share Posted May 7, 2004 piemers: function phpHighlight($code){ $code = "<?php\n".$code."\n?>"; $code = stripslashes($code); $code = highlight_string($code, true); $code = explode('<br />', $code); $text = "<table style='padding:0px; border-spacing: 0px 0px;'>"; for($x=0;$x<sizeof($code);$x++) $text .= "<tr><td style='font-family:Verdana; font-size:10px; vertical-align:middle; background-color:#FFFFE1;'>". ($x+1)."</td><td>". $code[$x]."</td></tr>"; $text .= "</table>"; return $text; } $data = "<p>Shis ir texts un pa vidu ir [kods]<?php echo 'BLABLA '; ?>[/kods]</p>"; $code_start = strPos($data, "[kods]"); $code_end = strPos($data, "[/kods]"); $code = substr($data, $code_start, ($code_end - $code_start)); $code = str_replace("[kods]", "", $code); echo phpHighlight($code); Nu pec butibas butu jaatgriezh To <?php kodu ?> Smuku un krasainu! Nesmu pameginajis, jo esmu skolaa, bet vajadzetu iet. Vel tur ir tada lieta, ka strPos, kursh stringa tev atrod to [kods] un [/kods] Nesmu parliecinats, ka shis viss stradas, ja stringaa buus vairaki [kods] [/kods] Bet tu to vari parbaudit Link to comment Share on other sites More sharing options...
sviesc Posted May 7, 2004 Author Report Share Posted May 7, 2004 jā to kodu attlēlo smuku un krāsainu, bet pārējo tekstu norij :( Link to comment Share on other sites More sharing options...
sviesc Posted May 7, 2004 Author Report Share Posted May 7, 2004 (edited) tipa tika atrasts kopīgīs risinājums, bet problēmas sāka rasties ar "gf" un 'fg' lietošanu $s = 'blaa blaa [kods]blaa print("sadasd");blaa[/kods blaa blaa'; $start = '\[kods\]'; $end = '\[\/kods\]'; $s = preg_replace("/$start([^$end]*)$end/e", 'phpHighlight("\1")', $s); $s = stripslashes($s); echo $s; ir kādas idejas? Edited May 7, 2004 by sviesc Link to comment Share on other sites More sharing options...
Gacha Posted May 11, 2004 Report Share Posted May 11, 2004 Nu es mocijos un mocijos, bet nekādi nevaru izdabūt to pašu, ko tu Sviesc mēģināji: $data = preg_replace("(\[kods\](.+?)\[\/kods\])is","<blockquote>$1</blockquote>",$data); Nu šeit redzams, ka tas $1 ir tas texts iekš tām iekavām tb. kods. Bet nekādi nevaru piedabūt viņu pie phphighlight($1), jo sanāk, ka tas ir kads iekšējais mainīgais preg_repleisam un $cipars nedrīkst izmantot. Mēģināju $kods = '$1'; bet arī nekā. Un manuālī arī šis nebija apspriests. Varbūt kāds iz dzīves var pateikt ? Link to comment Share on other sites More sharing options...
bubu Posted May 11, 2004 Report Share Posted May 11, 2004 tak manuaalii ir piemeers: http://lv.php.net/manual/en/function.preg-...ce-callback.php un tavaa gadiijumaa buus: (nepaarbaudiiju, tikai doma) function phpHighlight($match) // $match masiivs ar atrastajiem gabaliem { return "<blockquote>$match[0]</blockquote>"; } $data = preg_replace("(\[kods\](.+?)\[\/kods\])is", "phpHighlight",$data); Link to comment Share on other sites More sharing options...
Gacha Posted May 12, 2004 Report Share Posted May 12, 2004 Es meginaju to preg_replace tad preg_replace_callback bet nesanaak. vinjsh man izmet araa tikai phphighlight un viss :( Te ir: function phphighlight($code){ $code = stripslashes($code); $code = highlight_string($code, true); return $code; } un $data = preg_replace("(\[kods\](.+?)\[\/kods\])is","</p><blockquote><p>$1</p></blockquote><p>",$data); Šos man vajag sajūgt kopā, bet nesanāk. Link to comment Share on other sites More sharing options...
Recommended Posts